ใช้ # วางคอมเมนต์ได้ทุกบรรทัดในคำสั่ง SQL
ตัวอย่าง CREATE TABLE พร้อมคอมเมนต์
mysql> create table DemoTable
-> (
-> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY , # Creating a sequence Number
-> FirstName varchar(20), # Creating a column to store name
-> Age int # creating a column to store an age
-> );
Query OK, 0 rows affected (1.43 sec)
INSERT พร้อมคอมเมนต์
mysql> insert into DemoTable(FirstName,Age) values('Chris',21);
Query OK, 1 row affected (0.54 sec)
mysql> insert into DemoTable(FirstName,Age) values('David',23); # Inserting to store Firstname and age.
Query OK, 1 row affected (0.42 sec)
mysql> insert into DemoTable(FirstName,Age) values('Bob',24); # Inserting to store Firstname and age.
Query OK, 1 row affected (0.30 sec)
ผลลัพธ์
mysql> select * from DemoTable;
+----+-----------+------+ | Id | FirstName | Age | +----+-----------+------+ | 1 | Chris | 21 | | 2 | David | 23 | | 3 | Bob | 24 | +----+-----------+------+ 3 rows in set (0.00 sec)
รูปแบบคอมเมนต์ใน MySQL: # comment (จบบรรทัด) | -- comment (จบบรรทัด ต้องมีช่องว่างหลัง --) | /* comment */ (หลายบรรทัด) | ใช้ได้ใน CREATE TABLE, INSERT, SELECT ทุกคำสั่ง