Quick SQL Reference

SQL has a unique set of guidelines called Syntax. Quick SQL Reference gives you a jump start with SQL by listing all the basic SQL Syntax.

Query

Syntax

CREATE DATABASE query

CREATE DATABASE database_name;
      

CREATE TABLE query

CREATE TABLE table_Name(
column_Name_1 dataType,
column_Name_2 dataType,
column_Name_3 dataType,
...
column_Name_X dataType,
PRIMARY KEY(one or more columns)
);
      

INSERT INTO query

INSERT INTO table_Name_1 column_Name_2, column_Name_3...column_Name_X)
VALUES (value_1, value_2...value_X);
      

SELECT query

SELECT column_Name_1, column_Name_2...column_Name_X
FROM table_Name;
      

SELECT DISTINCT query

SELECT DISTINCT column_Name_1, column_Name_2...column_Name_X
FROM table_Name;
      

WHERE clause

SELECT column_Name_1, column_Name_2...column_Name_X
FROM table_Name
WHERE condition;
      

AND and OR clause

SELECT column_Name_1, column_Name_2...column_Name_X
FROM table_Name
WHERE condition_One {AND|OR} condition_Two;
      

IN clause

SELECT column_Name_1, column_Name_2...column_Name_X
FROM table_Name
WHERE column_Name IN (value_one, value_two,...value_X);
      

BETWEEN clause

SELECT column_Name_1, column_Name_2...column_Name_X
FROM table_Name
WHERE column_Name BETWEEN value_one AND value_two;
      

LIKE clause

SELECT column_Name_1, column_Name_2...column_Name_X
FROM table_Name
WHERE column_Name LIKE {PATTERN};
      

ORDER BY clause

SELECT column_Name_1, column_Name_2...column_Name_X
FROM table_Name
WHERE condition
ORDER BY column_Name {ASC|DESC};
      

COUNT clause

SELECT COUNT(column_Name)
FROM table_Name
WHERE condition;
      

CREATE INDEX query

CREATE UNIQUE INDEX index_Name
ON table_Name (column_Name_1, column_Name_2...column_Name_X);
      

DROP INDEX query

ALTER TABLE table_name
DROP INDEX index_name;
      

DESC clause

DESC table_name;
      

ALTER TABLE query

ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};
      

ALTER TABLE RENAME query

ALTER TABLE table_name RENAME TO new_table_name;
      

UPDATE query

UPDATE table_name
SET column_Name_1 = value_1, column_Name_2 = value_2... column_Name_X=value_X
[WHERE condition];
      

DELETE query

DELETE FROM table_Name
WHERE {condition};
      

TRUNCATE TABLE query

TRUNCATE TABLE table_name;
      

DROP TABLE query

DROP TABLE table_Name;
      

DROP DATABASE query

DROP DATABASE database_name;
      

USE query

USE database_name;
      

COMMIT query

COMMIT;
      

ROLLBACK query

ROLLBACK;
      
Quick SQL Reference