删除,截断或删除以清理MySQL中的表 [英] Delete, Truncate or Drop to clean out a table in MySQL

查看:78
本文介绍了删除,截断或删除以清理MySQL中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试清理表,但没有摆脱表的实际结构.我有一个自动递增的id列;我不需要保留ID号,但确实需要它来保持其自动递增特性.我发现了删除和截断功能,但我担心其中之一会完全删除整个表,从而使将来的插入命令变得毫无用处.

I am attempting to clean out a table but not get rid of the actual structure of the table. I have an id column that is auto-incrementing; I don't need to keep the ID number, but I do need it to keep its auto-incrementing characteristic. I've found delete and truncate but I'm worried one of these will completely drop the entire table rendering future insert commands useless.

如何从表中删除所有记录,以便可以插入新数据?

How do I remove all of the records from the table so that I can insert new data?

推荐答案

TRUNCATE将重置您的自动增量种子(至少在InnoDB表上),尽管您可以在截断之前记下它的值,然后相应地进行重新设置.使用变更表:

TRUNCATE will reset your auto-increment seed (on InnoDB tables, at least), although you could note its value before truncating and re-set accordingly afterwards using alter table:

ALTER TABLE t2 AUTO_INCREMENT = value

这篇关于删除,截断或删除以清理MySQL中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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