将注释放在 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 命令向表中插入一些记录。我们还将使用相同的 # 符号在 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)
使用 select 语句从表中显示所有记录 -
mysql> select *from DemoTable;
将产生以下输出 -
+----+-----------+------+ | Id | FirstName | Age | +----+-----------+------+ | 1 | Chris | 21 | | 2 | David | 23 | | 3 | Bob | 24 | +----+-----------+------+ 3 rows in set (0.00 sec)
广告