在 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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2021-12-30
  • 2021-11-13
  • 2022-12-23
猜你喜欢
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-06-05
  • 2022-03-10
相关资源
相似解决方案