1

I'm following a tutorial here. It keeps using '@' characters in front of stuff. Can I just confirm... does '@' identify variables within a query?

Thanks,

James

5 Answers 5

2

SET is used to give the variable an initial value.

For example:

SET @row := 0;

SELECT (@row := @row + 1) AS row, name FROM table;

If we don't give the variable an initial value, it would be NULL.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - perfect explanation. Welcome to Stackoverflow :)
2

It names a so-called "user variable".

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

Comments

2

Yes, '@' is used as a prefix for user defined variables. Find more information here

Comments

1

Yup. MySQL's documentation has a section about user-defined variables. You typically declare them with SET in MySQL, however I've seen other kinds of SQL use DECLARE.

Comments

1

Ahh, this is actually how you declare variables in mysql. Look at here:

http://dev.mysql.com/tech-resources/articles/mysql-storedproc.html

The first thing we need to understand is how user variables are used and assigned values. A user variable is distinguished by having a '@' symbol in front of it, and values are assigned using the SET statement:

4 Comments

@BoltClock - I do not appreciate rude comments. He never did mention in what context.
Intriguing - the tutorial I'm following uses stuff like SELECT @myRight := rgt FROM nested_category. Is that OK to use too?
Figured as much. I admit I was rather impatient, so I'll apologize. @JamWaffles, you may want to add an example snippet so it's clearer what you're referring to.
My bad - sorry to both of you :-) The original question, however, has been answered many times in this thread.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.