select column_name, data_type, is_nullable, description.description as comment from information_schema.columns columns left join pg_class class on (columns.table_name = class.relname) left join pg_description description on (class.oid = description.objoid) left join pg_attribute attrib on (class.oid = attrib.attrelid and columns.column_name = attrib.attname and attrib.attnum = description.objsubid) where table_name=’{$tableName}’ group by ordinal_position, column_name, data_type, is_nullable, description.description
发布评论
评论(4)
oracle这样获取:
//获得表注释
select * from user_table_comments where table_name='table_name';
//获取列注释
select * from user_col_comments where table_name='table_name';
我分享postgreSQL的获取注释方法吧:
select
column_name,
data_type,
is_nullable,
description.description as comment
from
information_schema.columns columns
left join pg_class class on (columns.table_name = class.relname)
left join pg_description description on (class.oid = description.objoid)
left join pg_attribute attrib on (class.oid = attrib.attrelid and columns.column_name = attrib.attname and attrib.attnum = description.objsubid)
where
table_name=’{$tableName}’
group by
ordinal_position, column_name, data_type, is_nullable, description.description
1、取得表注释
Select table_name 表名,TABLE_COMMENT 表注释 from INFORMATION_SCHEMA.TABLES Where table_schema = 'testhuicard' # #数据库名
AND table_name LIKE 'companies' # #表名
参考http://dev.mysql.com/doc/refman/5.1/zh/information-schema.html.
mysql手册:23.1. INFORMATION_SCHEMA表
2、取字段注释
Select COLUMN_NAME 列名, DATA_TYPE 字段类型, COLUMN_COMMENT 字段注释
from INFORMATION_SCHEMA.COLUMNS
Where table_name = 'companies' # #表名
AND table_schema = 'testhuicard' # #数据库名
AND column_name LIKE 'c_name' # #字段名
3、取得某数据库下所有表的注释
$tt = mysql_query("show table status;");
$table_info=array();
while($re = mysql_fetch_array($tt,MYSQL_ASSOC)){
//$re["Comment"],这个就是表的注释
$table_info[] = $re;
} ......
mysql的
select TABLE_COMMENT from information_schema.tables where table_name="temp";
+-----------------------+
| TABLE_COMMENT |
+-----------------------+
| 临时表 |
+-----------------------+
1 row in set (0.00 sec)
是要这样的吗