对表中的 字段 一些基本操作
- 将某个字段修改为null;
alter table 表名 modify 字段名 字段类型 default null;
- 为某个表增添一个字段;
alter table 表名 add 字段名 字段类型 not null default 0;
- 为某个表修改 数据类型;
alter table 表名 change 字段名 新的字段类型;
- 为表增添索引;
ALTER TABLE 表名 ADD INDEX(字段名);
- 为表添加唯一列;
alter table 表名 add unique 字段名 ;
- 从表中删除一个字段;
alter table 表名 drop 字段名;
- 为表的主键增添自增功能;
alter table 表名 change 字段名 字段名 字段类型 [primary key] auto_increment
这里的[primary key] 是依情况而定,如果此字段已经定义主键,则不需要再声明主键