Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

Is there any way to reset all the sequences of tables, when postgres truncate tables on cascade.

Asked by Grace Duncan Oct 3, 2022 3.7K views 1 answer
Share

About this question

 Is there any way to reset all the sequences of tables, when truncate a table on cascade.

I already read this post: How to reset sequence in postgres and fill id column with new data?

ALTER SEQUENCE seq RESTART WITH 1;

UPDATE t SET id column=nextval('seq');

It works only for one sequence, but my problem is to restart all the sequences of the truncated tables.

Consider when I use TRUNCATE sch.mytable CASCADE; It affects 3 related tables, which mean three sequences. Is there any solution to restart this sequence in one shot?

Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.