PostgreSQL : Truncate table with restart PK Auto increment value

Database

It’s very easy to truncate table in any database but all database have some uniqueness in each of them. I have written this quick tip to show how we can truncate table in PostgreSQL with restarting primary key auto increment value.

Here is the simple command to truncate table but it won’t reset the autoincrement value of a primary key.

1
TRUNCATE "table_name";

Here is the trick to truncate a table and restart primary key value.

1
TRUNCATE "table_name" RESTART IDENTITY;
0 0 vote
Article Rating

Tags: #PostgreSQL

Related Post

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments