Placing comments in the middle of a create table statement? Is it possible?



Yes, it is possible using the # symbol. Let us first create a 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)

Above, we have set comments using the # symbol. Insert some records in the table using insert command. We will set comments in insert statement as well using the same # symbol −

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)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+----+-----------+------+
| Id | FirstName | Age  |
+----+-----------+------+
|  1 | Chris     |   21 |
|  2 | David     |   23 |
|  3 | Bob       |   24 |
+----+-----------+------+
3 rows in set (0.00 sec)

Advertisements