postgresql 清空数据表数据

在 mysql中,只需要执行:

TRUNCATE table_name;

即可,数据会情况,而且自增id也会变回0;

但在 postgresql 则稍有不同,因为 postgresql 的自增id是通过序列 sequence来完成的,

所以情况数据后,还需要还原序列 sequence:

TRUNCATE bigtable, fattable RESTART IDENTITY;

官方文档:https://www.postgresql.org/docs/9.2/static/sql-truncate.html

另一种方式:(因为版本不同,可能命令不同)

truncate table table_name;
alter sequence seq_name start 1;

参考:https://stackoverflow.com/questions/13989243/sequence-does-not-reset-after-truncating-the-table

posted @ 2018-07-25 14:48  一菲聪天  阅读(29866)  评论(0编辑  收藏  举报