2

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.

Andrew
  • 227,796
  • 193
  • 515
  • 708

3 Answers3

3

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
  • 14,998
  • 7
  • 42
  • 68
  • 2
    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 Jan 11 '10 at 18:25
  • 2
    @Nick, that's dependent on the SQL server, though. I believe MySQL uses back ticks instead of square brackets. – Paul Tomblin Jan 11 '10 at 18:26
  • 1
    anything after -- on the same line is always a comment – D'Arcy Rittich Jan 11 '10 at 18:26
  • 1
    Can also to be used as character classes in an regex like expressions: `SELECT * FROM Table WHERE field like 'caf[eéèëê]'` – Rubens Farias Jan 11 '10 at 18:28
0

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

Sampson
  • 265,109
  • 74
  • 539
  • 565
0

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
  • 413,100
  • 91
  • 616
  • 614