John Hunt's web log | Open source, Linux, Developer tips, Beer, Whatever

Jul/09

14

Auto_increment fun!

Discovered some fun things in MySQL today..

Set the variable @id to 0:
SET @id = 0;

Update the column id to be id + 1 – this will re-index your id column in one fell swoop. Very nice:
UPDATE tblname SET id = (@id := @id + 1);

Set the first value for an auto_increment column:
ALTER TABLE tblname AUTO_INCREMENT = 196;
(this won’t work if there are rows with a higher value already in the table)

All in all, a few nice bits and pieces for cleaning up your tables.

RSS Feed

No comments yet.

Leave a comment!

<<

>>

Find it!

Theme Design by devolux.nh2.me