我們如何使用 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 千次 + 瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

開始學習
廣告