Comments:
Comments
suggest changeThe -- style of comment, which requires a trailing space, differs in behavior from the SQL standard, which does not require the space.
Adding comments
There are three types of comment:
# This comment continues to the end of line
-- This comment continues to the end of line
/* This is an in-line comment */
/*
This is a
multiple-line comment
*/
Example:
SELECT * FROM t1; -- this is comment
CREATE TABLE stack(
/* id_user int,
username varchar(30),
password varchar(30)
*/
id int
);
The -- method requires that a space follows the -- before the comment begins, otherwise it will be interpreted as a command and usually cause an error.
# This comment works
/* This comment works. */
-- This comment does not.
Commenting table definitions
CREATE TABLE menagerie.bird (
bird_id INT NOT NULL AUTO_INCREMENT,
species VARCHAR(300) DEFAULT NULL COMMENT 'You can include genus, but never subspecies.',
INDEX idx_species (species) COMMENT 'We must search on species often.',
PRIMARY KEY (bird_id)
) ENGINE=InnoDB COMMENT 'This table was inaugurated on February 10th.';
Using an = after COMMENT is optional. (Official docs)
These comments, unlike the others, are saved with the schema and can be retrieved via SHOW CREATE TABLE or from information_schema.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents
5
Insert
10
Delete
11
View
14
Comments
17
ALTER TABLE
18
Joins
19
UPDATE
21
JSON
22
MySQL Admin
23
TRIGGERS
27
SELECT
29
Group By
30
UNION
31
Drop Table
32
Data Types
34
Events
35
ENUM
37
Arithmetic
42
Log files
43
Partitioning
45
Backticks
46
mysqlimport
48
MySQL Unions
49
ORDER BY
50
MySQL client
53
Transaction
57
NULL
58
Replication
68
One to Many
72
Contributors