1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| CREATE TABLE table (field1 type1, field2 type2, ...) CREATE TABLE table (field1 type1 unsigned not null auto_increment, field2 type2, ...) CREATE TABLE table (field1 type1, field2 type2, ..., INDEX (field)) CREATE TABLE table (field1 type1, field2 type2, ..., PRIMARY KEY (field1)) CREATE TABLE table (field1 type1, field2 type2, ..., PRIMARY KEY (field1, field2)) CREATE TABLE table1 (fk_field1 type1, field2 type2, ..., FOREIGN KEY (fk_field1) REFERENCES table2 (t2_fieldA) [ON UPDATE] [CASCADESET NULLRESTRICT] [ON DELETE] [CASCADESET NULLRESTRICT]) CREATE TABLE table1 (fk_field1 type1, fk_field2 type2, ..., FOREIGN KEY (fk_field1, fk_field2) REFERENCES table2 (t2_fieldA, t2_fieldB)) CREATE TABLE table IF NOT EXISTS (...)
CREATE TABLE new_tbl_name LIKE tbl_name [SELECT ... FROM tbl_name ...]
CREATE TEMPORARY TABLE table (...)
CREATE table new_table_name as SELECT [ *column1, column2 ] FROM table_name
DROP TABLE table DROP TABLE IF EXISTS table DROP TABLE table1, table2, ... DROP TEMPORARY TABLE table
ALTER TABLE table MODIFY field1 type1 ALTER TABLE table MODIFY field1 type1 NOT NULL ... ALTER TABLE table CHANGE old_name_field1 new_name_field1 type1 ALTER TABLE table CHANGE old_name_field1 new_name_field1 type1 NOT NULL ... ALTER TABLE table ALTER field1 SET DEFAULT ... ALTER TABLE table ALTER field1 DROP DEFAULT ALTER TABLE table ADD new_name_field1 type1 ALTER TABLE table ADD new_name_field1 type1 FIRST ALTER TABLE table ADD new_name_field1 type1 AFTER another_field ALTER TABLE table DROP field1 ALTER TABLE table ADD INDEX (field); ALTER TABLE table ADD PRIMARY KEY (field);
ALTER TABLE table MODIFY field1 type1 FIRST ALTER TABLE table MODIFY field1 type1 AFTER another_field ALTER TABLE table CHANGE old_name_field1 new_name_field1 type1 FIRST ALTER TABLE table CHANGE old_name_field1 new_name_field1 type1 AFTER another_field
ALTER TABLE old_name RENAME new_name;
|