Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Monday, 7 February 2011

Some say MySQL does not have any sequences

Not true, it's got only one, and it's per session:

select last_insert_id(last_insert_id() + 1);


To be reset like that:

select last_insert_id(0);

Thursday, 23 September 2010

MySQL: Changing the order of a table column

In an ideal purely standard SQL world, one should never have to care about the order of a table's columns. But we're not in an ideal world, and sometime we want to change the position of a table column. Here's how to do it:


ALTER TABLE mytable MODIFY column_move <WHATEVER TYPE IT IS>  AFTER another_column

Note that you need to MODIFY the column with its exact type not to loose any data. Copy/Pasting is your friend here. You can also use BEFORE instead of after.