mysql创建自增字段

2021-01-15 20:14:26  阅读 2828 次 评论 0 条

ZT https://blog.csdn.net/cc996/article/details/69399736

1、创建表格时添加: create table tablename(id int auto_increment primary key,...) 

2、创建表格后添加: alter table tablename add id int auto_increment primary key
3、设置主键:alter table tablename add primary key(field_name);
4、重命名表: alter table table_old_name rename table_new_name;
5、改变字段的类型:alter table tableName modify field_name field_type;
6、重命名字段:alter table tableName change old_field_name new_field_name new_field_type;
7、删除字段:alter table tableName drop column field_name;
8、增加一个新字段:alter table tableName add new_field_name field_type;   
                                  alter table tableName add new_field_name field_type not null default '0';
9、新增一个字段,默认值为0,非空,自动增长,主键:alter table tabelname add new_field_name field_type default 0 not null   auto_increment ,add primary key (new_field_name);   

创建一个表
create table pre_common_usernotes (id int(8) not null primary key auto_increment, user_id char(20) not null, order_id char(20) not null, pub_id char(20) not null, ad_name char(20) , ad_id int(8), device char(20) , system_name char(20), channel int(8), price double(16,2), point int(8), ts int(10) not null default'0', sign char(30));

创建数据库并设置数据库默认字段编码格式
create database database_name default charset utf8 collate utf8_unicode_ci;

设置 auto_increment字段 的最小值
ALETER TABLE table_name AUTO_INCREMENT=100000


本文地址:https://jinesc.net/?id=253
版权声明:本文为原创文章,版权归 jinesc 所有,欢迎分享本文,转载请保留出处!

发表评论


表情

还没有留言,还不快点抢沙发?