PostgreSQL : Truncate table with restart PK Auto increment value

It’s very easy to truncate tables in any database but all databases have some uniqueness in each of them. I have written this quick tip to show how we can truncate tables in PostgreSQL with restarting primary key autoincrement 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 the primary key value.

1
TRUNCATE "table_name" RESTART IDENTITY;

About the Author: Avinash

Experienced full stack freelance web developer with a track record of producing excellent results for 11+ years. Excellent communication and collaboration skills, managing with a team of 20+ people. I’m motivated to make a positive impact on your revenue through the customer web portal development project.

Leave A Comment

FREE QUOTE

Do you need help with services? Request a free quote to get in touch.