[PostgreSQL] Truncate Table and Reset Sequence

If we need that after TRUNCATE table, also reset the SEQUENCE then we can do this step :

1. Set the minimum value of the sequence

alter sequence mytable_id_seq minvalue 0 start with 1;

2. Now either reset it:

SELECT setval('mytable_id_seq', 0)

OR we can reset it while truncating:

truncate mytable restart identity;




Artikel Terkait :

1 comments:

erectile dysfunction treatment said...

I'd like to thank you for the efforts you've put in writing this website. I really hope to check out the same high-grade content by you later on as well. In truth, your creative writing abilities has encouraged me to get my very own blog now ;)