删除所有数据后将主键重置为1 [英] Resetting the primary key to 1 after deleting all the data

查看:101
本文介绍了删除所有数据后将主键重置为1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有MySql,我有一个带有user_id列的表用户,它是主键并自动递增.现在,当我从表中删除所有数据并添加新数据时,user_id不是从1开始,而是从删除之前的数字开始.如果我想重置它而不丢弃整个表并再次创建该怎么办?

So i have MySql and i have a table user with a user_id column and it is the primary key and auto incremented. Now when i delete all my data from the table and add the new one, the user_id does not start from 1 but from the number it had before deletion. What if i want to reset it without dropping the whole table and creating it again.

推荐答案

ALTER TABLE some_table AUTO_INCREMENT=1

所以some_table将是您要更改的表.

So some_table would be the table you want to alter.

您还可以使用:

TRUNCATE TABLE some_table

这将重置表上的自动增量,并从该表中删除所有记录.

This will reset the Auto Increment on the table as well as deleting all records from that table.

这篇关于删除所有数据后将主键重置为1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆