技术改变生活

博客园 首页 新随笔 联系 订阅 管理
mysql> alter table a1 change id idname int(20) unsigned not null;

  修改表字段属性关键字change,语法:alter table  表名  change  旧字段名称   新字段名称   新字段属性;需要注意地方,unsigned 必须紧跟在int属性后面,否则会提示报错

 

mysql> create table a2 ( id int unsigned auto_increment primary key ); 

  auto_increment自增长字段属性特性,要求该字段类型必须为主键(primary key),否则会创建失败

mysql> alter table a1 add password varchar(50) not null default '123456' after work;
Query OK, 0 rows affected (0.01 sec)

  default 默认值字段属性特性,需要注意的是,默认值需要使用   ’单引号括起来,否则会报错。after表示跟在某个字段的后面。

mysql> alter table a1 add primary key(id);
Query OK, 0 rows affected (0.01 sec)

  primary key为字段添加主键索引,需要注意的是,要添加的主键索引字段需要用()括起来,否则报错。

posted on 2020-06-22 17:05  小阿峰  阅读(375)  评论(0编辑  收藏  举报