MySQL User defined Variables – good thing to know!

2009 April 2
by tobi

Have you ever heard of user defined variables in MySQL? I hadn’t and nearly freaked out when I found out. That’s the thing I was always looking for, that’s so cool, and fasten up your SQL live a lot!

Now, renumbering a table is as easy as never before:

Set @a = 0;
UPDATE my_table SET id=@a:=@a+1

Check out the docu and examples:

http://dev.mysql.com/doc/refman/5.0/en/user-variables.html

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS