Skip to content

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:

[text]
Set @a = 0;
UPDATE my_table SET id=@a:=@a+1
[/text]

Check out the docu and examples:
http://dev.mysql.com/doc/refman/5.0/en/user-variables.html

Flattr this!

One Response
  1. June 20, 2011

    By using User-defined variables, one can add some kind of procedural logic to the MySQL’s relational logic.
    See some examples http://www.mysqldiary.com/user-defined-variables/

Comments are closed.