在 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