mysql常用操作——Alter

操作 语法 示例 注意
修改表名 ALTER TABLE table_name RENAME TO new_table_name alter table testcjq rename to testsuper;
增加字段 ALTER TABLE table_name ADD field_name field_type alter table testsuper add aclomn varchar(10) default null;
修改字段 ALTER TABLE table_name MODIFY field_name field_type alter table testsuper modify aclomn varchar(20);
修改字段名称及类型 ALTER TABLE table_name CHANGE old_field_name new_field_name field_type; alter table testsuper change aclomn bclomn int; 修改一个字段的名称,此时一定要重新指定该字段的类型
删除字段 ALTER TABLE table_name DROP field_name; alter table testsuper drop bclomn;
添加主键索引 ALTER TABLE table_name ADD PRIMARY KEY ( column ) alter table testsuper add primary key (T_ID);
添加唯一索引 ALTER TABLE table_name ADD UNIQUE ( column ) alter table testsuper add UNIQUE (T_IE);
alter table testsuper add UNIQUE index u1 (T_ID,TC_IE);//联合唯一索引别名为u1的联合索引
添加普通索引 ALTER TABLE table_name ADD INDEX ( column ) alter table testsuper add index (T_IF);
添加全文索引 ALTER TABLE table_name ADD FULLTEXT ( column ) alter table testsuper add fulltext (T_IH);
添加联合索引 ALTER TABLE table_name ADD INDEX index_name ( column1, column2, column3 ) alter table testsuper add index st (T_IM,T_IN);

猜你喜欢

转载自blog.csdn.net/u010811939/article/details/85103819