1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| # 标识列
# 创建表时,设置某列为标识列 DROP TABLE IF EXISTS tab_identify; CREATE TABLE tab_identify( id INT PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR(20) );
TRUNCATE TABLE tab_identify;
INSERT INTO tab_identify VALUES(NULL,'Leslie'); INSERT INTO tab_identify VALUES(NULL,'Jesie');
SELECT * FROM tab_identify;
SET auto_increment_increment=3; # 设置步长,修改为每次增加3个 SHOW VARIABLES LIKE '%auto_increment%'; # 查看当前系统步长和起始值
# 修改表时设置标识列,起始本质还是修改表的类型 ALTER TABLE tab_identify MODIFY COLUMN id INT UNIQUE AUTO_INCREMENT;
|