达梦、Oracle、PostgreSQL查询全部表备注,表字段,全部字段备注,全部索引,全部字段类型
针对达梦、Oracle和PostgreSQL数据库,查询表的备注、表字段、字段备注、所有索引及所有字段的SQL语句分别如下:
- 达梦数据库(DM):
查询表备注:
SELECT table_name, comments FROM user_tab_comments WHERE table_name = '表名';
查询表字段:
SELECT column_name, data_type, comments FROM user_col_comments WHERE table_name = '表名';
查询字段备注:
SELECT column_name, comments FROM user_col_comments WHERE table_name = '表名';
查询所有索引:
SELECT index_name, index_type, table_name FROM user_indexes WHERE table_name = '表名';
查询所有字段:
SELECT column_name FROM user_tab_columns WHERE table_name = '表名';
- Oracle数据库:
查询表备注:
SELECT table_name, comments FROM user_tab_comments WHERE table_name = '表名';
查询表字段:
SELECT column_name, data_type, comments FROM user_col_comments WHERE table_name = '表名';
查询字段备注:
SELECT column_name, comments FROM user_col_comments WHERE table_name = '表名';
查询所有索引:
SELECT index_name, index_type, table_name FROM user_indexes WHERE table_name = '表名';
查询所有字段:
SELECT column_name FROM user_tab_columns WHERE table_name = '表名';
- PostgreSQL数据库:
查询表备注:
SELECT description FROM pg_description WHERE objoid = '表的OID'::oid AND objsubid = 0;
查询表字段:
SELECT column_name, data_type, col_description(table_name::regclass, column_name::text) AS comments FROM information_schema.columns WHERE table_name = '表名';
查询字段备注:
SELECT col.table_name, col.column_name, des.description
FROM information_schema.columns col
LEFT JOIN pg_description des ON (des.objoid = col.table_name::regclass AND des.objsubid = col.ordinal_position)
WHERE col.table_name = '表名';
查询所有索引:
SELECT indexname, indexdef FROM pg_indexes WHERE tablename = '表名';
查询所有字段:
SELECT column_name FROM information_schema.columns WHERE table_name = '表名';
注意:在以上SQL语句中,需要将'表名'替换为实际的表名。对于Oracle和PostgreSQL,表名可能需要大写,因为这些数据库在内部存储时通常会将表名转换为大写。对于达梦数据库,表名通常是大小写不敏感的,但如果创建表或查询时使用了双引号,则需要在查询时也使用大写并加上双引号。
评论已关闭