MySQL 如何创建一个以1000开始且带有自动增量的INT字段(不是主键)
为此,您需要将AUTO_INCREMENT设置为1000 –
alter table yourTableName AUTO_INCREMENT = 1000;
Mysql
首先让我们创建一个表 –
mysql> create table DemoTable639 (
StudentId int PRIMARY KEY,
StudentStartId int AUTO_INCREMENT,
StudentName VARCHAR(50),
INDEX(StudentStartId)
);
Query OK, 0 rows affected (0.86 sec)
Mysql
以下是设置自动增量为1000的查询 –
mysql> alter table DemoTable639 AUTO_INCREMENT = 1000;
Query OK, 0 rows affected (0.28 sec)
Records: 0 Duplicates: 0 Warnings: 0
Mysql
使用insert命令在表中插入一些记录 –
mysql> insert into DemoTable639(StudentId,StudentName) values(1,'John');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable639(StudentId,StudentName) values(2,'Chris');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable639(StudentId,StudentName) values(3,'Robert');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable639(StudentId,StudentName) values(4,'David');
Query OK, 1 row affected (0.16 sec)
Mysql
使用select语句从表中显示所有记录 –
mysql> select *from DemoTable639;
Mysql
这将产生以下输出 –
+-----------+----------------+-------------+
| StudentId | StudentStartId | StudentName |
+-----------+----------------+-------------+
| 1 | 1000 | John |
| 2 | 1001 | Chris |
| 3 | 1002 | Robert |
| 4 | 1003 | David |
+-----------+----------------+-------------+
4 rows in set (0.00 sec)
Mysql
阅读更多:MySQL 教程