
2、创建表格后添加: alter table table1 add id int auto_increment primary key 自增字段,一定要设置为primary key.
附:mysql 中的alter table mysql>alter table employee change depno depno int(5) not null
加索引 mysql>alter table 表名 add index 索引名 (字段名1[,字段名2 …])
例子: mysql>alter table employee add index emp_name (name)
加主关键字的索引 mysql>alter table 表名 add primary key (字段名)
例子: mysql>alter table employee add primary key(id)
加唯一限制条件的索引 mysql>alter table 表名 add unique 索引名 (字段名)
例子: mysql>alter table employee add unique emp_name2(cardnumber)
查看某个表的索引 mysql>show index from 表名例子: mysql>show index from employee
删除某个索引 mysql>alter table 表名 drop index 索引名例子: mysql>alter table employee drop index emp_name
修改表:增加字段:mysql>ALTER TABLE table_name ADD field_name field_type
查看表:mysql>SELECT * FROM table_name
修改原字段名称及类型:mysql>ALTER TABLE table_name CHANGE old_field_name new_field_name field_type
删除字段:ALTER TABLE table_name DROP field_name
怎么给mysql的字段设置自动递增1
清空所有数据,将自增去掉,存盘,在加上自增,存盘,就从1开始了
如何让mysql的自动编号从1开始
2
truncate
table
你的表名
这样不但将清除数据,而且可以重新位置identity属性的字段
不过以上都不能保留现有数据哦。
在要求自增长的字段加入自增约束, auto_increment. 这个字段不用输入内容自动增加,初始1 ,每次增加1例如: create table abc(id int(5) primary_key auto_increment)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)