mysql、postgresql查询表字所有字段
1、mysql查询表字所有字段
- 第一种:
SHOW FULL COLUMNS FROM table_name;
解释:
Field :字段名
Type:字段类型
Collation:字符集(mysql 5.0以上有)
Null :是否可以为NULL
Key:索引(PRI,unique,index)
Default:缺省值
Extra:额外(是否 auto_increment)
Privileges:权限
Comment:备注(mysql 5.0以上有)
- 第二种:
SELECT
COLUMN_NAME 列名,
COLUMN_COMMENT 名称,
COLUMN_TYPE 数据类型,
DATA_TYPE 字段类型,
CHARACTER_MAXIMUM_LENGTH 长度,
IS_NULLABLE 是否必填,
COLUMN_DEFAULT 描述
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
table_schema = 'dbname'
AND table_name = 'table'
2、postgresql查看表字段
SELECT a.attnum,
a.attname AS field,
t.typname AS type,
a.attlen AS length,
a.atttypmod AS lengthvar,
a.attnotnull AS notnull,
b.description AS comment
FROM pg_class c,
pg_attribute a
LEFT OUTER JOIN pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid,
pg_type t
WHERE c.relname = 't_uc_login'
and a.attnum > 0
and a.attrelid = c.oid
and a.atttypid = t.oid
ORDER BY a.attnum;