我们如何使用 MySQL 的 ALTER TABLE 命令在列上添加注释?


我们可以将“COMMENT”关键字与 ALTER TABLE 命令一起使用,在修改列时在列上添加注释。例如,如果我们要在表“testing”的“id”列中添加注释,那么可执行以下查询指令来完成操作 −

mysql> ALTER TABLE testing MODIFY id INT COMMENT 'id of employees';
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0

执行以下查询指令可以在列的注释字段中进行检查。

mysql> Show full columns from testing\G
*************************** 1. row ***************************
     Field: id
      Type: int(11)
 Collation: NULL
      Null: NO
       Key: PRI
   Default: 0
     Extra:
Privileges: select,insert,update,references
   Comment: id of employees
*************************** 2. row ***************************
     Field: Name
      Type: varchar(20)
 Collation: latin1_swedish_ci
      Null: YES
       Key:
   Default: NULL
     Extra:
Privileges: select,insert,update,references
   Comment:
2 rows in set (0.05 sec)

更新时间: 2020-1 月 29 日

1 千次 + 浏览

开启你的 职业生涯

完成课程即可获得认证

开始学习
广告
© . All rights reserved.