MySQL设置自增字段的方法介绍

如何实现MySQL设置自增字段是许多人都问到的问题,下面就为您介绍MySQL设置自增字段的相关知识,希望对您学习MySQL数据库能有所启迪。

MySQL设置自增字段的相关语句:

alter table album change ALBUM_ID ALBUM_ID bigint not null auto_increment;
alter table album auto_increment=1;

创建:
mysql>create table cc(id int auto_increment,name varchar(20),primary key(id));
修改:
mysql> alter table cc change id id int primary key auto_increment;

注:只有int类型且为primary key 才可以使用auto_increment.

》》》》》》》》》》》》》》》》》》》》》》》》》》》》

MySQL添加字段的方法并不复杂,下面将为您详细介绍MySQL添加字段和修改字段等操作的实现方法,希望对您学习MySQL添加字段方面会有所帮助。

1.登录数据库
>mysql -u root -p 数据库名称

2.查询所有数据表
>show tables;

3.查询表的字段信息
>desc 表名称;

4.1添加表字段

alter table table1 add transactor varchar(10) not Null;

alter table   table1 add id int unsigned not Null auto_increment primary key

4.2.修改某个表的字段类型及指定为空或非空
>alter table 表名称 change 字段名称 字段名称 字段类型 [是否允许非空];
>alter table 表名称 modify 字段名称 字段类型 [是否允许非空];

>alter table 表名称 modify 字段名称 字段类型 [是否允许非空];

4.3.修改某个表的字段名称及指定为空或非空
>alter table 表名称 change 字段原名称 字段新名称 字段类型 [是否允许非空

4.4如果要删除某一字段,可用命令:ALTER TABLE mytable DROP 字段 名;

posted @ 2013-04-25 11:25  Tim&Blog  阅读(2027)  评论(0编辑  收藏  举报