SQL Flashcards
What is SQL and where is it used?
SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving data stored in a relational database.
SQL is the standard language for Relational Database System. All the Relational Database Management Systems (RDMS) like MySQL, MS Access, Oracle, Sybase, Informix, Postgres and SQL Server use SQL as their standard database language.
What are the different dialects of SQL
MS SQL Server using T-SQL,
Oracle using PL/SQL,
MS Access version of SQL is called JET SQL (native format) etc
What are the functionalities of SQL?
Allows users to access data in the relational database management systems.
Allows users to describe the data.
Allows users to define the data in a database and manipulate that data.
Allows to embed within other languages using SQL modules, libraries & pre-compilers.
Allows users to create and drop databases and tables.
Allows users to create view, stored procedure, functions in a database.
Allows users to set permissions on tables, procedures and views.
What commands make up DDL
CREATE
ALTER
DROP
What commands make up DML?
SELECT
INSERT
UPDATE
DELETE
What commands make up DCL
GRANT
REVOKE
Syntax to create a database and then check for it in the list of databases
CREATE DATABASE DatabaseName;
SQL> SHOW DATABASES;
Syntax to delete database
DROP DATABASE DatabaseName;
Syntax to choose a certain database before beginning your operations
USE DatabaseName;
Syntax to create a tabe
CREATETABLEPersons (PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) );
Give a list of the MYSQL data types
Varchar Tinytext Blob Int Tinyint Bigint Double Date Datetime Timestamp
Syntax to insert values into the database
INSERT INTO TABLE_NAME (column1,column2,column3,…columN)
VALUES (value1,value2,value3,…valueN);
Syntax to populate one table using another table
INSERT INTO first_table[(column1,column2,…columnN)]
SELECT column1,column2,…,columnN
FROM second_table
[WHERE condition];
Syntax for the select statement
SELECT column1, column2, columnN FROM table_name;
If you want to fetch all the fields available in the field, then you can use the following syntax.
SELECT * FROM table_name;
Syntax of the select ..where statement with both one and many conditions
SELECT ID, NAME, SALARY
FROM CUSTOMERS
WHERE SALARY > 2000;
*Many conditions
SELECT column1, column2, columnN
FROM table_name
WHERE [condition1] AND[condition2]…AND [conditionN];
*Instead of and one may also use OR