MYSQL-修改数据表1

添加单列

ALTER TABLE tbl_name ADD [COLUMN] col_name column_definition [FIRST|AFTER col_name]

添加多列

(不能指定位置关系)

ALTER TABLE tbl_name ADD  [COLUMN] (col_name column_definition,...)

删除列

ALTER TABLE tbl_name DROP  [COLUMN] col_name

删除多列

ALTER TABLE tbl_name DROP  [COLUMN] col_name,DROP  [COLUMN] col_name,...

添加主键约束

ALTER TABLE tbl_name ADD [CONSTRAINT[symbol]] PRIMARY KEY [index_type] (index_col_name,...)

添加唯一约束

ALTER TABLE tbl_name ADD  [CONSTRAINT[symbol]]  UNIQUE  [INDEX|KEY] [index_name] [index_type] (index_col_name,...)

添加外键约束

ALTER TABLE tbl_name ADD  [CONSTRAINT[symbol]]  FOREIGN KEY  [index_name] (index_col_name,...) reference_definition

添加/删除默认约束

ALTER TABLE tbl_name ALTER [COLOUMN] col_name {SET DEFAULT literal|DROP DEFAULT}

删除主键约束

ALTER TABLE tbl_name DROP PRIMARY KEY

删除唯一约束

ALTER TABLE tbl_name DROP {INDEX|KEY} index_name

查看约束名字:SHOW INDEXS FROM tbl_name

删除外键约束

ALTER TABLE tbl_name DROP FROEIGN KEY fk_symbol

查看建表语句:SHOW CREATE TABLE tbl_name

你可能感兴趣的:(MYSQL-修改数据表1)