Reset PostgreSQL primary key to 1

前端 未结 3 900
野的像风
野的像风 2020-12-07 08:49

Is there a way to reset the primary key of a PostgreSQL table to start at 1 again on a populated table?

Right now it\'s generating numbers from 1000000 and up. I wan

3条回答
  •  情话喂你
    2020-12-07 09:41

    The best way to reset a sequence to start back with number 1 is to execute the following:

    ALTER SEQUENCE __seq RESTART WITH 1
    

    So, for example for the users table it would be:

    ALTER SEQUENCE users_id_seq RESTART WITH 1
    

提交回复
热议问题