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

Cách thêm chú thích (comment) cho cột trong bảng MySQL hiện có

Có thể thêm comment cho cột bằng từ khóa COMMENT khi sửa đổi cột với ALTER TABLE. 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 comment 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)

Cột id hiện có comment id of employees.