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:

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

Check out the docu and examples:

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

Comments are closed.