SQL Flashcards
Types of databases ?
- 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 …
what is RDBMS ?
mySQL, Oracle , postgreSQL, mariaDB…It performs CRUD operations and makes it easy to create , maintain and secure a DB.
what is NRDBMS ?
mongoDB, dynamoDB, firebase ,…
What is SQL ?
- 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
What is a database query ?
A query is a request made to the RDBMS for a specific information .(A google search is a query )
What is a primary key ?
It is an attribut which uniquely identifies a row in the DB
what is a foreign key ?
It stores the primary key of another DB table , allows us to define relationships between databases
What are the data types in SQL ?
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’
What is the command to create a database named giraffe ?
CREATE DATABASE girrafe;
What is the command to create a table named student with student_id , name and major attributes ?
CREATE TABLE student ( Student_id INT PRIMARY KEY, OR Name VARCHAR(20), Major VARCHAR(20) ) ;
What is the command to delete a table named student ?
DROP TABLE student;
how to create a new column named gpa in the student table ?
ALTER TABLE student ADD gpa DECIMAL(3,2); //it creates a new gpa column
How to delete the gpa column from the student table ?
ALTER TABLE student DROP COLUMN gpa;
How to display the structure of the table ?
DESCRIBE student ;
- How to insert a row with id 1 , name jack and major biology
- How to insert a row with id 1 , name jack.
INSERT INTO student VALUES (1,’jack’,biology);
or
INSERT INTO student (student_id,name) VALUES(‘1,jack’)