Mysql 操作字段

对表中的 字段 一些基本操作

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

猜你喜欢

转载自blog.csdn.net/qq_37384795/article/details/84661387