MySQL建表时添加备注以及查看某一张表的备注信息

建表的时候对列和表明添加备注:

DROP TABLE IF EXISTS test_table;

CREATE TABLE test_table (
	ID INTEGER AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
	NAME VARCHAR(20) COMMENT '姓名'
) COMMENT = '测试表';

查看表中列的备注信息:

SELECT   
    column_name AS '列名',  
    data_type   AS '数据类型',   
    character_maximum_length  AS '字符长度',   
    numeric_precision AS '数字长度',       
    numeric_scale AS '小数位数',   
    is_nullable AS '是否允许非空',   
    CASE   
        WHEN extra = 'auto_increment' THEN 1
        ELSE 0   
    END AS '是否自增',   
    column_default  AS  '默认值',   
    column_comment  AS  '备注'   
FROM   
    information_schema.columns   
WHERE   
    table_name='test_table';

查看当初怎么建这张表的:

SHOW CREATE TABLE test_table;
posted @ 2018-05-23 17:01  zifeiy  阅读(13054)  评论(0编辑  收藏  举报