This is a draft cheat sheet. It is a work in progress and is not finished yet.
Modify Table Fields
ALTER TABLE table MODIFY field1 field_def [ FIRST | AFTER other_field ] |
ALTER TABLE table CHANGE old_name new_name field_def [ FIRST | AFTER other_field ] |
ALTER TABLE table ALTER field1 SET DEFAULT value |
ALTER TABLE table ALTER field1 DROP DEFAULT |
ALTER TABLE table ADD new_field1 field_def [ FIRST | AFTER other_field ] |
ALTER TABLE table DROP field1 |
ALTER TABLE table ADD INDEX (field); |
ALTER TABLE table ADD PRIMARY KEY (field); |
|
|
Update Data
UPDATE table1 SET field1 = value1 [ WHERE condition ] [ ORDER BY field ] [ LIMIT lim ] |
UPDATE table1 JOIN table2 ON id1 = id2 SET field1 = value1, field2 = value2, ... [ WHERE condition ] |
Delete Data
DELETE FROM table WHERE condition [ ORDER BY field ] [ LIMIT lim ] |
DELETE alias1, alias2 FROM table1 alias1 JOIN table2 alias2 ON id1 = id2 ... WHERE condition |
|
|
|