Reputation: 61
I'm using -- and # for comments in my SQL scripts but when I run, it returns error messages about syntax errors. When I take the comments out it runs fine. For examples below cause errors.
#################################################
# DELETE RECORDS FROM TABLE
#################################################
-- DELETE RECORDS FROM TABLE WHERE EXTRACT RECORDS CONTAIN DELETE
The only comment I can do is # at the beginning of a line which I guess is sufficient but I want to know why this doesn't work. Did this all the time in SQLServer.
Upvotes: 4
Views: 3996
Reputation: 12206
Both ways are acceptable for commenting out lines in MySQL scripts. See MySQL's documentation on comments. The hash at the start of the line is acceptable, as is the double-hyphen as long as it is followed by a space, e.g.:
-- This line is valid a comment
Not putting a space after the double hyphen will cause errors in mysql.
--This line is NOT a valid comment
If you are putting a space after the double-hyphens, there must be some other reason for the syntax errors. The example you posted works for me in MySQL without errors.
Upvotes: 6
Reputation: 4917
According to the documentation # is allowed for comments but you may need to add a space between the first and the second one eg: # ######
Upvotes: 0
Reputation: 485
Try to do this otherwhise..
-- #################################################
-- # DELETE RECORDS FROM TABLE
-- #################################################
-- DELETE RECORDS FROM TABLE WHERE EXTRACT RECORDS CONTAIN DELETE
Upvotes: 0
Reputation: 59997
Comments in SQL start --
i.e. What you have and that works
But not starting with '#'
So put --
to start a comment
This is when the database is running in ANSI mode (I guess)
Upvotes: 1