PostgreSQL : Truncate table with restart PK Auto increment value

  • Avinash
  • 0
  • Nov 25, 2016
  • 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.

TRUNCATE "table_name";
TRUNCATE "table_name";

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

TRUNCATE "table_name" RESTART IDENTITY;
TRUNCATE "table_name" RESTART IDENTITY;

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by: