Mysql
CREATE TABLE YH ( id int PRIMARY KEY COMMENT '主键id', name varchar(50) NOT NULL COMMENT '姓名', age int COMMENT '年龄' ) COMMENT '用户表';
SELECT TABLE_COMMENT AS '表注释', TABLE_ROWS AS '表中的行数(估计值)', CREATE_TIME AS '表创建时间', UPDATE_TIME AS '表最后修改时间' FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'YH';
SELECT ORDINAL_POSITION AS '序号', COLUMN_NAME AS '列名', DATA_TYPE AS '类型', COLUMN_TYPE AS '详细类型', CASE COLUMN_KEY WHEN 'PRI' THEN '主键' WHEN 'UNI' THEN '唯一索引' WHEN 'MUL' THEN '非唯一索引' ELSE COLUMN_KEY END AS '索引', IS_NULLABLE AS '是否为 NULL', COLUMN_COMMENT AS '注释' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'YH';
CREATE PROCEDURE GetTables( IN TABLESCHEMA varchar(50) ) BEGIN SELECT TABLE_NAME AS '表名', TABLE_COMMENT AS '表注释', '' AS '序号', '' AS '列名', '' AS '注释', '' AS '类型', '' AS '详细类型', '' AS '索引', '' AS '是否为 NULL' FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = TABLESCHEMA AND TABLE_NAME = DATABASE() UNION SELECT '' AS '表名', '' AS '表注释', ORDINAL_POSITION AS '序号', COLUMN_NAME AS '列名', COLUMN_COMMENT AS '注释', DATA_TYPE AS '类型', COLUMN_TYPE AS '详细类型', CASE COLUMN_KEY WHEN 'PRI' THEN '主键' WHEN 'UNI' THEN '唯一索引' WHEN 'MUL' THEN '非唯一索引' ELSE COLUMN_KEY END AS '索引', IS_NULLABLE AS '是否为 NULL' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = TABLESCHEMA AND TABLE_NAME = DATABASE(); END
CALL GetTables('YH');