从MySQL表中删除数据后如何自动加1?
为此,您可以使用TRUNCATE TABLE命令。让我们首先创建一个表-
mysql> create table DemoTable1796(
StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
StudentName varchar(20)
);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1796(StudentName) values('Chris Brown');mysql> insert into DemoTable1796(StudentName) values('David Miller');
mysql> insert into DemoTable1796(StudentName) values('John Doe');
使用select语句显示表中的所有记录
mysql> select * from DemoTable1796;
这将产生以下输出
+-----------+--------------+| StudentId | StudentName |
+-----------+--------------+
| 1 | Chris Brown |
| 2 | David Miller |
| 3 | John Doe |
+-----------+--------------+
3 rows in set (0.00 sec)
这是从表中删除记录的查询-
mysql> delete from DemoTable1796;
现在将记录插入表中
mysql> insert into DemoTable1796(StudentName) values('John Doe');mysql> select * from DemoTable1796;
+-----------+-------------+
| StudentId | StudentName |
+-----------+-------------+
| 4 | John Doe |
+-----------+-------------+
1 row in set (0.00 sec)
现在您可以使用TRUNCATE TABLE命令
mysql> truncate table DemoTable1796;
现在,让我们将一些记录插入表中
mysql> insert into DemoTable1796(StudentName) values('John Doe');mysql> select * from DemoTable1796;
+-----------+-------------+
| StudentId | StudentName |
+-----------+-------------+
| 1 | John Doe |
+-----------+-------------+
1 row in set (0.00 sec)
以上是 从MySQL表中删除数据后如何自动加1? 的全部内容, 来源链接: utcz.com/z/316295.html