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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With