Question

I found an example of the nested set model that I am trying to use on a project. I can't understand just a small part of what is happening which in turn makes it so I can't tweak it to my needs. The example looks like this:

LOCK TABLE nested_category WRITE;

SELECT @myRight := rgt FROM nested_category
WHERE name = 'TELEVISIONS';

UPDATE nested_category SET rgt = rgt + 2 WHERE rgt > @myRight;
UPDATE nested_category SET lft = lft + 2 WHERE lft > @myRight;

INSERT INTO nested_category(name, lft, rgt)
VALUES ('GAME CONSOLES', @myRight + 1, @myRight + 2);

UNLOCK TABLES;

I don't understand what is going on in on the line SELECT @myRight:=rgt FROM nested_category. More specifically, I am not grasping "@myRight := rgt". What is going on there?

Était-ce utile?

La solution

It looks like the code is assigning the value of rgt from the row in nested_category where name = 'TELEVISIONS' to the variable @myRight.

Autres conseils

This is assignment operator in mysql. Read this http://dev.mysql.com/doc/refman/5.0/en/assignment-operators.html

SELECT @myRight := rgt FROM nested_category

Variable myRight will be filled with the value from column rgtin table nested_category

User-Defined Variables are supported in at least MySQL and Transact-SQL.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top