数据表修改
2018-02-05 本文已影响0人
mejhwu
添加单列
ALTER TABLE table_name ADD [COLUMN] column_name column_definition [FIRST | AFTER colomn_name]
添加多列
ALTER TABLE table_name ADD [COLUMN](column_name column_definition, ...)
删除列
ALTER TABLE table_name DROP column_name1, DROP column_name2, ...
添加主键约束
ALTER TABLE table_name ADD[CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_column_name,...)
添加唯一约束
ALTER TABLE table_name ADD [CONSTRAINT [symbol]]
UNIQUE [INDEX|KEY] [index_name] [index_type](index_column_name,...)
添加外键约束
ALTER TABLE table_name ADD [CONSTRAINT [symbol]]
FOREIGN KEY [index_name] (index_column_name,...) reference_definition
添加/删除默认约束
ALTER TABLE table_name ALTER [COLUMN] column_name {SET DEFAULT literal | DROP DEFAULT}
删除主键约束
ALTER TABLE table_name DROP PRIMARY KEY
删除唯一约束
ALTER TABLE table_name DROP {INDEX | KEY} index_name
删除外键约束
ALTER TABLE table_name DROP FOREIGN KEY kf_name
修改列定义
ALTER TABLE table_name
{MODIFY | CAHNGE} [COLUMN] column_name column_definition [FIRST | AFTER column_name]
修改列名称
ALTER TABLE table_name
MODIFY [COLUMN] old_column_name new_column_name column_definition [FIRST | AFTER column_name]
数据表更名
ALTER TABLE table_name RENAME [TO|AS] new table_name
RENAME TABLE table_name TO new_table_name [, table_name2 TO new_table_name2]...