我是靠谱客的博主 等待羊,这篇文章主要介绍在MySQL中创建表时在表中设置AUTO_INCREMENT?,现在分享给大家,希望可以做个参考。

让我们首先创建一个表。我们在创建表时使用了AUTO_INCREMENT来设置StudentId的自动增量-

复制代码
1
2
3
4
5
6
7
8
9
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;

使用插入命令在表中插入一些记录-

复制代码
1
2
3
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语句显示表中的所有记录-

复制代码
1
mysql> select *from DemoTable;

输出结果

复制代码
1
2
3
4
5
6
7
+-----------+------------------+-----------------+------------+--------------------+ | 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?的全部内容,更多相关在MySQL中创建表时在表中设置AUTO_INCREMENT内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(93)

评论列表共有 0 条评论

立即
投稿
返回
顶部