5
I had already realized that mysql, maybe not even the only case, but I would like an explanation on top of this to be more objective.
I have several types of comments that are accepted:
1) -- ESTA LINHA ESTA COMENTADA ?
2) # ESTA LINHA ESTA COMENTADA ?
3) /*ESTA LINHA ESTA COMENTATA
E CONTINUA COMENTADA*/
4) /*!40101 SET character_set_client = utf8 */;
I know I can use both option 1 and 2 to comment on a single line and 3 and 4 for multiple lines but I still have to understand other details.
My question is/are:
- Using -- or # makes a difference, have some recommendation when using one or the other?
- Are the instructions contained in 4) executed even commented? If yes, what is the reason for placing them inside the comment if it is possible to do them outside it?
I think to win +1, it remains to mention that only
--
is ANSI SQL - the other comment types are Mysql extensions, and writing code using other comment types will make it harder to migrate to another DBMS in the future.– user25930
@ctgPi this should be described in detail in the documentation, so I left the links there :)
– Paulo Roberto
@Pauloroberto read in the documentation and understood that it is recommended to use # and not -- to which credit-! payment! don’t become 1-1 and turn a comment, ok but regarding sql statements run inside the comment I didn’t find anything there
– SneepS NinjA
@Sneepsninja you didn’t say the language you’re using, and I know it’s another database, but e.g. psycopg2 (Postgresql driver for Python) serializes 2 as
"2"
but -2 as" -2"
(note the space); I wouldn’t be surprised if other drivers had similar logic to treat this case.– user25930