在MySQL中创建表时在表中设置AUTO_INCREMENT?
让我们首先创建一个表。我们在创建表时使用了AUTO_INCREMENT来设置StudentId的自动增量-
mysql> create table DemoTable-> (
-> StudentId int NOT NULL AUTO_INCREMENT,
-> StudentFirstName varchar(100),
-> StudentLastName varchar(100),
-> StudentAge int,
-> StudentCountryName varchar(100),
-> PRIMARY KEY(StudentId)
-> )AUTO_INCREMENT=30;
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(StudentFirstName,StudentLastName,StudentAge,StudentCountryName) values('John','Smith',21,'US');mysql> insert into DemoTable(StudentFirstName,StudentLastName,StudentAge,StudentCountryName) values('Chris','Brown',20,'AUS');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+-----------+------------------+-----------------+------------+--------------------+| StudentId | StudentFirstName | StudentLastName | StudentAge | StudentCountryName |
+-----------+------------------+-----------------+------------+--------------------+
| 30 | John | Smith | 21 | US |
| 31 | Chris | Brown | 20 | AUS |
+-----------+------------------+-----------------+------------+--------------------+
2 rows in set (0.00 sec)
以上是 在MySQL中创建表时在表中设置AUTO_INCREMENT? 的全部内容, 来源链接: utcz.com/z/326633.html