MySQL FAQs
FAQs Categories
Client Server Commands
Database Structure
Table Types or Storage Engines
Indexes
SQL Statements
Table Joins
Funtions and Operators
Tricky Select Queries
Speed Up Queries
Data Back Up
General Questions
Errors
N.M.P.L. Company www.NearMePayday.Loan || 3-month (90 days)
Powered by MySQL
 
Home / Question No: 227

How to use comments in SQL statements?

Answer No: 227

MySQL supports three forms of comment syntax. One of those forms has variants that allow special instructions to be passed through to the MySQL server.

  • A '#' character begins a comment that extends to the end of the line. This commenting style is like that used by several other programs, such as Perl, Awk, and several Unix shells.
  • A /* sequence begins a comment that ends with a */ sequence. This style is the same as that used for writing comments in the C programming language. A C-style comment may occur on a single line or span multiple lines:
    /* this is a comment */
    
    /*
      this
      is a
      comment,
      too
    */
    
  • A -- (double dash) sequence followed by a space (or control character) begins a comment that extends to the end of the line. This syntax requires a space and thus differs from standard SQL syntax, which allows comments to be introduced by -- without the space. MySQL disallows a double dash without a space as a comment because it's ambiguous. (For example, does 1--3 mean "one minus negative three" or "one followed by a comment"?)

C-style comments can contain embedded SQL text that's treated specially by the MySQL server, but ignored by other database engines. This is an aid to writing more portable SQL because it enables you to write comments that are treated as part of the surrounding statement if executed by MySQL and ignored if executed by other database servers. There are two ways to write embedded SQL in a C-style comment:

  • If the comment begins with /*! rather than with /*, MySQL executes the body of the comment as part of the surrounding query. The following statement creates a table named t, but for MySQL creates it specifically as a MEMORY table:
    CREATE TABLE t (i INT) /*! ENGINE = MEMORY */;
  • If the comment begins with /*! followed by a version number, the embedded SQL is version specific. The server executes the

Related MySQL FAQs to the Above FAQ

How-to-do-numeric-sorting-within-a-string-field-in-MySQL How to do numeric sorting within a string field in MySQL?

How-can-I-detect-that-MySQL-is-already-installed How can I detect that MySQL is already installed?

What-is-prepared-statement-in-MySQL What is prepared statement in MySQL?

What-is-MySQL-date-format-and-its-specifiers What is MySQL date format and its specifiers?

Why-I-see-an-error-when-I-EXPLAIN-for-update-query Why I see an error when I EXPLAIN for update query?

Maximum-number-of-columns-in-a-table Maximum number of columns in a table

What-is-better-query-to-update-a-table What is better query to update a table?

Can-I-use-FIELD-CONSTRAINTS-on-MySQL Can I use FIELD CONSTRAINTS on MySQL?

How-to-get-all-dates-between-two-dates How to get all dates between two dates?

How-to-speed-up--multi-table-based-delete-query How to speed up multi table based delete query?

ERROR-1295-(HY000):-This-command-is-not-supported-in-the-prepared-statement-protocol-yet ERROR 1295 (HY000): This command is not supported in the prepared statement protocol yet

How-to-get-comma-separated-all-values-in-a-single-row-against-each-ID How to get comma separated all values in a single row against each ID?

How-to-take-data-back-up-of-single-table How to take data back up of single table?

How-to-find-duplicate-records-from-a-table-in-MySQL How to find duplicate records from a table in MySQL?

Why-my-update-query-works-slow-in-MySQL Why my update query works slow in MySQL?

ERROR-1064-(42000):-You-have-an-error-in-your-SQL-syntax ERROR 1064 (42000): You have an error in your SQL syntax

What-are-reserved-words-in-MySQL What are reserved words in MySQL?

How-to-get-last-top-records-in-asceding-order How to get last top records in asceding order?

How-to-move-table-from-one-to-another-MySQL-database How to move table from one to another MySQL database?

How-to-get-parent-table-child-table-and-grandchild-table-aggregates-in-MySQL How to get parent table child table and grandchild table aggregates in MySQL?

How-to-skip-repeating-values-from-the-query-results How to skip repeating values from the query results?

How-to-retrieve--one-child-row-against-each-parent-id How to retrieve one child row against each parent id?

An-important-trick-to-speed-up-select-query An important trick to speed up select query.

How-to-find-the-books-which-have-authors-with-more-than-one-book-in-the-table How to find the books which have authors with more than one book in the table?

1264-Out-of-range-value-adjusted-for-column 1264 Out of range value adjusted for column

What-is-BIT-Data-Type-in-MySQL What is BIT Data Type in MySQL?

What-are-numeric-data-types-in-MySQL What are numeric data types in MySQL?

What-are-integer-data-types-in-MySQL What are integer data types in MySQL?

What-are-float-data-types-in-MySQL What are float data types in MySQL?

What-is-fixed-point-and-decimal-data-type-in-MySQL What is fixed point and decimal data type in MySQL?

How-to-concat-values-in-MySQL How to concat values in MySQL?

What-is-MySQL-default-character-set What is MySQL default character set?

What-is-difference-between-binary-and-non-binary-string-data-types What is difference between binary and non-binary string data types?

What-are-ENUM-and-SET-Data-Types-in-MySQL What are ENUM and SET Data Types in MySQL?

What-is-difference-between-CHAR-AND-VARCHAR-data-types What is difference between CHAR AND VARCHAR data types?

About FAQs: Recently Added FAQs

About MySQL FAQs: Site Map | Bookmark Us | Recommend this Site to Your Friend | Contact Us

Useful Links: Wikipedia.org | Oracle.com | w3schools.com | www.php.net | Github.com

© 2021  www.mysqlfaqs.net
All rights reserved.