tags:

views:

203

answers:

3

I am looking at a note that someone wrote to me and it looks something like this:

SELECT Something FROM Foobar WHERE blah='blah'  --- [pulls this too - SELECT Something FROM Foobar WHERE something='elsehappens']

I'm trying to figure out if the --- [ comment - QUERY] is just a comment or if it actually means something I haven't seen before.

+3  A: 

In this case it is just a comment... square brackets are often used to delimit real names for reserved words, or simply to delimit actual identifiers, but anything after a -- is always a comment.

Michael Bray
Brackets are also used to treat space-separated words as one. E.G. if a column is called Text Entry you would have to do SELECT * FROM [Text Entry]
Nick
@Nick, that's dependent on the SQL server, though. I believe MySQL uses back ticks instead of square brackets.
Paul Tomblin
anything after -- on the same line is always a comment
RedFilter
Can also to be used as character classes in an regex like expressions: `SELECT * FROM Table WHERE field like 'caf[eéèëê]'`
Rubens Farias
A: 

They are generally used to indicate optional words or clauses. In this example, it appears to be nothing more than a comment as indicated in the manual: MySQL Comment Syntax

Jonathan Sampson
A: 

In MySQL, a -- comment is just a comment.

C-style comments with special characters may be used to give hints to the query optimizer, run version-specific queries etc:

CREATE TABLE mytable (id INT) /*!50000 ENGINE=InnoDB */ ;

This will create the table as InnoDB in MySQL 5.0 or higher, or with default engine in MySQL below 5.0.

Quassnoi