Sequence does not reset after truncating the table

前端 未结 6 1825
礼貌的吻别
礼貌的吻别 2021-01-31 16:18

I use SELECT lastval() to get wrong serial id after truncated the table.

when I truncate the table, I use SELECT lastval(), I got the wrong ID/

6条回答
  •  生来不讨喜
    2021-01-31 16:43

    Try

    TRUNCATE TABLE table_name 
    RESTART IDENTITY;
    

    It will

    Automatically restart sequences owned by columns of the truncated table(s).

    Details here: TRUNCATE

提交回复
热议问题