1. 程式人生 > >mysql 建立表新增行、列註釋

mysql 建立表新增行、列註釋

建立表添加註釋

CREATE TABLE purchase(
                id int(25) PRIMARY KEY AUTO_INCREMENT, 
                user_id int(50) COMMENT'列註釋',  
                created_on  datetime default NULL
            )ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='表註釋';

查看錶註釋:

SELECT tableName,tableComment 
    FROM
information_schema.tables WHERE table_schema = '所在db' AND table_name = '表名稱';
或者: SHOW CREATE TABLE purchase;

修改註釋

ALTER TABLE purchase COMMENT '新的表註釋';
ALTER TABLE purchase MODIFY COLUMN user_id VARCHAR(25) COMMENT '新的列註釋';

檢視列註釋

SHOW FULL COLUMNS FROM purchase;
也可安條件查詢
SHOW FULL
COLUMNS FROM purchase WHERE FIELD = 'user_id' OR TYPE LIKE '%int%' -- 檢視purchase表中列名是user_id的或型別是int的列