Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> MySQL

Cách dùng ALTER TABLE thêm comment cho cột MySQL

Có thể dùng từ khóa COMMENT với lệnh ALTER TABLE khi sửa đổi cột để thêm chú thích. Ví dụ thêm comment cho cột id của bảng testing:

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

Kiểm tra bằng SHOW FULL COLUMNS:

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)