SQL Statements |
Grammar |
and/or |
SELECT column_name (s) From table_name WHERE condition And|or condition |
ALTER TABLE |
ALTER TABLE table_name ADD column_name datatypeOr ALTER TABLE table_name DROP COLUMN column_name |
As (alias) |
SELECT column_name as Column_alias From table_nameOr SELECT column_name From table_name as Table_alias |
Between |
SELECT column_name (s) From table_name WHERE column_name Between Value1 and value2 |
CREATE DATABASE |
CREATE DATABASE database_name |
CREATE TABLE |
CREATE TABLE table_name ( Column_name1 Data_type, Column_name2 Data_type, Column_name2 Data_type, ... ) |
CREATE INDEX |
CREATE INDEX index_name On table_name (COLUMN_NAME)Or CREATE UNIQUE INDEX index_name On table_name (COLUMN_NAME) |
CREATE VIEW |
CREATE VIEW View_name as SELECT column_name (s) From table_name WHERE condition |
DELETE |
DELETE from table_name WHERE Some_column=some_valueOr DELETE from table_name (Note: deletes the entire table!!) DELETE * FROM table_name (Note: deletes the entire table!!) |
DROP DATABASE |
DROP DATABASE database_name |
DROP INDEX |
DROP INDEX table_name.index_name (SQL Server) DROP INDEX index_name on table_name (MS Access) DROP INDEX index_name (db2/oracle) ALTER TABLE table_name DROP INDEX index_name (MySQL) |
DROP TABLE |
DROP TABLE table_name |
GROUP by |
SELECT column_name, aggregate_function (column_name) From table_name WHERE column_name operator Value GROUP by column_name |
Having |
SELECT column_name, aggregate_function (column_name) From table_name WHERE column_name operator Value GROUP by column_name Having aggregate_function (column_name) operator value |
Inch |
SELECT column_name (s) From table_name WHERE column_name In (Value1,value2,..) |
INSERT into |
INSERT into table_name VALUES (value1, value2, Value3,....)Or INSERT into table_name (Column1, Column2, Column3,...) VALUES (value1, value2, Value3,....) |
INNER JOIN |
SELECT column_name (s) From table_name1 INNER JOIN table_name2 On Table_name1.column_name=table_name2.column_name |
Left JOIN |
SELECT column_name (s) From table_name1 Left JOIN table_name2 On Table_name1.column_name=table_name2.column_name |
Right JOIN |
SELECT column_name (s) From table_name1 Right JOIN table_name2 On Table_name1.column_name=table_name2.column_name |
Full JOIN |
SELECT column_name (s) From table_name1 Full JOIN table_name2 On Table_name1.column_name=table_name2.column_name |
Like |
SELECT column_name (s) From table_name WHERE column_name like pattern |
ORDER by |
SELECT column_name (s) From table_name ORDER by column_name [asc| DESC] |
SELECT |
SELECT column_name (s) From table_name |
SELECT * |
SELECT * From table_name |
SELECT DISTINCT |
SELECT DISTINCT column_name (s) From table_name |
SELECT into |
SELECT * into new_table_name [in Externaldatabase] From Old_table_nameOr SELECT column_name (s) into new_table_name [in Externaldatabase] From Old_table_name |
SELECT TOP |
SELECT TOP number|percent column_name (s) From table_name |
TRUNCATE TABLE |
TRUNCATE TABLE table_name |
UNION |
SELECT column_name (s) from table_name1 UNION SELECT column_name (s) from table_name2 |
UNION All |
SELECT column_name (s) from table_name1 UNION All SELECT column_name (s) from table_name2 |
UPDATE |
UPDATE table_name SET Column1=value, Column2=value,... WHERE Some_column=some_value |
WHERE |
SELECT column_name (s) From table_name WHERE column_name operator Value |