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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM