SQL Quick Reference
SQL Quick Reference
DROP table [IF EXISTS] tbl_name [,tbl_name] DML (Data Manipulation Language) SELECT [Distinct | DISTINCTROW | ALL] select_expression, [FROM table_references [WHERE where_definition] [HAVING where_definition] [ORDER BY {unsigned_integer | col_name | formula} | ASC | DESC] [LIMIT [offset] rows] [PROCEDURE procedure_name]] Table_references tbl_name, tbl_name tbl_name [CROSS] JOIN tbl_name tbl_name INNER JOIN tbl_name tbl_name STRAIGHT_JOIN tbl_name tbl_name LEFT [OUTER] JOIN tbl_name USING (column_list) tbl_name NATURAL LEFT [OUTER] JOIN tbl_name ALTER TABLE tbl_name after_spec [, alter_spec] Alter_spec ADD COLUMN | create_def [FIRST| AFTER col_name] or ADD [COLUMN] (create_def, create_def) or ADD INDEX [index_name] (index_col_name) or ADD PRIMARY KEY (index_col_name) or ADD UNIQUE [INDEX] [index_name] (index_col_name) or ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT} or CHANGE [COLUMN] old_col_name create_def or MODIFY [COLUMN] create_def or DROP [COLUMN] col_name or DROP PRIMARY KEY or DROP INDEX index_name or RENAME [AS] new_ tbl_name or table_options CREATE [UNIQUE] INDEX index_name ON tbl_name (col_name [(length)],) DROP INDEX index_name on tbl_name CREATE [AGGREGATE] FUNCTION function_name RETURNS {STRING|RETAIL|INTEGER} SONAME shared_library_name DROP FUNCTION function_name Programmatic SQL EXPLAIN tbl_name EXPLAIN SELECT select_options {DESCRIBE | DESC} tbl_name {col_name | wild} Transaction control COMMIT [WORK] ROLEBACK [WORK] Other CREATE VIEW view_name AS select_statement REPLACE VIEW view_name AS select_statement DROP VIEW view_name TRUNCATE TABLE "table_name"
INSERT [INTO] tbl_name[(col_name,)] VALUES (expression,),() INSERT [INTO] tbl_name (col_name,) SELECT INSERT [INTO] tbl_name SET col_name=expression, DELETE [LOW_PRIORITY] FROM tbl_name [WHRE where_definition] UPDATE tbl_name SET col_name = expr1, col_name2=expr2, [WHERE where_definition] DDL (Data Definition Language) CREATE TABLE tbl_name [(Create_definition,)] [table_options] Create_Definition Col_name type [NOT NULL|NULL] [DEFAULT default_value] [AUTO_INCREMENT] [PRIMARY KEY] [reference_definition] or PRIMARY KEY (index_col_name) or KEY [index_name] (index_col_name) or INDEX [index_name] (index_col_name) or UNIQUE [INDEX] [index_name] (index_col_name) or [CONSTANT symbol] FOREIGN KEY index_name (index_col_name) or CHECK (expr)