SQL Flashcards

1
Q

Types of databases ?

A
  • Relational Dabases : use SQL language and store data in Tables with columns and rows.
    • Non-Relational Databases ( noSQL ) : stores data using other data structures , key-value , JSON documents , XML documents, Graphs …
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is RDBMS ?

A

mySQL, Oracle , postgreSQL, mariaDB…It performs CRUD operations and makes it easy to create , maintain and secure a DB.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is NRDBMS ?

A

mongoDB, dynamoDB, firebase ,…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is SQL ?

A
  • It is a language for interacting with RDBMS
    • Used for CRUD operations and other administrative tasks (security , backup …)
    • It is a hybrid language : DQL+DDL+DCL+DML
    • DQL: Used to query DB and get information from the DB
    • DDL : defines DB schemas
    • DCL: control access to the data in the DB
  • DML : Insert, update and delete data from the DB
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a database query ?

A

A query is a request made to the RDBMS for a specific information .(A google search is a query )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a primary key ?

A

It is an attribut which uniquely identifies a row in the DB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is a foreign key ?

A

It stores the primary key of another DB table , allows us to define relationships between databases

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the data types in SQL ?

A

INT
DECIMAL(m,n): //m is the number of digits and n is the number of digits after the decimal
VARCHAR(n): n is the strength of the string
BLOB : for images and files and large objects
DATE: ‘yyyy-mm-dd’
TIMESTAMP :’yyyy-mm-dd hh:mm:ss’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the command to create a database named giraffe ?

A

CREATE DATABASE girrafe;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the command to create a table named student with student_id , name and major attributes ?

A
CREATE TABLE student (
		Student_id INT PRIMARY KEY,               OR
		Name VARCHAR(20),
		Major VARCHAR(20)
	) ;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the command to delete a table named student ?

A

DROP TABLE student;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how to create a new column named gpa in the student table ?

A

ALTER TABLE student ADD gpa DECIMAL(3,2); //it creates a new gpa column

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to delete the gpa column from the student table ?

A

ALTER TABLE student DROP COLUMN gpa;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to display the structure of the table ?

A

DESCRIBE student ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  • How to insert a row with id 1 , name jack and major biology
  • How to insert a row with id 1 , name jack.
A

INSERT INTO student VALUES (1,’jack’,biology);
or
INSERT INTO student (student_id,name) VALUES(‘1,jack’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to display the content of a student table

A

SELECT * FROM student ;

17
Q

Create a table with the use the NOT NULL , DEFAULT,UNIQUE constraints
and insert a row

A

CREATE TABLE student (
Student_id INT PRIMARY KEY ,
Name VARCHAR(20) NOT NULL,
Major VARCHAR(20) UNIQUE,
FavoriteClass VARCHAR(20) DEFAULT ‘undecided’
);
INSERT INTO student(student_id,name,major) VALUES(1,’Jack’,’science);

18
Q

Use the AUTO INCREMENT constraint and insert 3 rows in the student table

A

CREATE TABLE student (
Student_id INT PRIMARY KEY AUTO_INCREMENT ,
Name VARCHAR(20),
Major VARCHAR(20)
);
INSERT INTO student( name ,major ) VALUES( ‘Jack’, ‘science’ );
INSERT INTO student( name ,major ) VALUES( ‘Kate’, ‘math ‘ );

19
Q

How to

- ->Change the biology major to Bio:

- ->Change the bio and chemistry majors to Biochemistry.
- ->Change the name and major of a specific row/student exp with the id of 6.
- ->Change all the majors to nothing  ( in all the rows) :
A

UPDATE student SET major=’bio’ WHERE major=’biology’;
UPDATE student SET major=”Biochemistry” WHERE major=’bio’ OR major=’chemistry’;
UPDATEstudentSETname=’Tom’,major=’undecided’WHEREstudent_id=6;

UPDATE student SET major='nothinng';