[MySQL/PostgreSQL]auto_incrementリセット

MySQLでauto_incrementをリセット

  • TRUNCATE TABLE table_name;
  • ALTER TABLE table_name AUTO_INCREMENT=1;

PostgreSQLでauto_incrementをリセット

select setval(‘シーケンス名’, 1, false)でリセットする。

pgdb=# \ds+ pg_healths_id_seq
                                   List of relations
 Schema |       Name        |   Type   | Owner | Persistence |    Size    | Description
--------+-------------------+----------+-------+-------------+------------+-------------
 public | pg_healths_id_seq | sequence | goapp | permanent   | 8192 bytes |
(1 row)

pgdb=# select * from pg_healths_id_seq ;
 last_value | log_cnt | is_called
------------+---------+-----------
       1483 |      26 | t
(1 row)

pgdb=# select setval('pg_healths_id_seq', 1, false);
 setval
--------
      1
(1 row)

pgdb=# select * from pg_healths_id_seq ;
 last_value | log_cnt | is_called
------------+---------+-----------
          1 |       0 | f
(1 row)

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です