SELECT
表名 = case when a.colorder=1 then d.name else '' end,
索引 = j.name,
表数据行数 = o.hs,
表说明 = case when a.colorder=1 then isnull(f.value,'') else '' end,
字段序号 = a.colorder,
字段名 = a.name,
标识 = case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end,
主键 = case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=a.id and name in (
SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then '√' else '' end,
类型 = b.name,
占用字节数 = a.length,
长度 = COLUMNPROPERTY(a.id,a.name,'PRECISION'),
小数位数 = isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
允许空 = case when a.isnullable=1 then '√'else '' end,
默认值 = isnull(e.text,''),
字段说明 = isnull(g.[value],'')
FROM
syscolumns a
left join
systypes b
on
a.xusertype=b.xusertype
inner join
sysobjects d
on
a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
left join
syscomments e
on
a.cdefault=e.id
left join
sys.extended_properties g
on
a.id=G.major_id and a.colid=g.minor_id
left join
sys.extended_properties f
on
d.id=f.major_id and f.minor_id=0
left join
(select a.name ,b.rows as hs
from sysobjects a inner join sysindexes b
on a.id = b.id
where a.type = 'u'
and b.indid in (0,1)
) o
on (d.name = o.name)
left join sys.objects as h
on d.name=h.name
left join sys.indexes as j on h.object_id=j.object_id
where h.type<>'s'
order by
a.id,a.colorder
---------------------------------------------------以上是sqlserver------------------------------------------------------------
SELECT
d.TABLE_NAME tbName ,
COALESCE(t.COMMENTS, ' ') tbDesc,
a.COLUMN_NAME columnName,
a.DATA_TYPE columnType,
a.DATA_LENGTH width,
a.DATA_SCALE precision,
d.NUM_ROWS,
decode(a.NULLABLE,'Y','0','1') notNull,
COALESCE(m.COMMENTS, ' ') comments,
decode(k.uniqueness,'UNIQUE','1','0') uniques,
COALESCE(k.index_name, ' ') indexName,
decode(k.key,'Y','1','0') masterKey
FROM
user_tab_columns a
INNER JOIN user_tables d on a.TABLE_NAME=d.TABLE_NAME
LEFT JOIN user_tab_comments t ON t.TABLE_NAME=d.TABLE_NAME
LEFT JOIN user_col_comments m ON m.COLUMN_NAME=a.COLUMN_NAME AND m.TABLE_NAME=d.TABLE_NAME
LEFT JOIN
(
SELECT e.index_name,u.TABLE_NAME,u.COLUMN_NAME,e.uniqueness,decode(p.constraint_name,NULL,'N','Y') key
from user_indexes e INNER JOIN user_ind_columns u ON e.index_name=u.index_name
LEFT JOIN ( select constraint_name from user_constraints where constraint_type='P' ) p ON e.index_name=p.constraint_name
) k ON k.TABLE_NAME=a.TABLE_NAME and k.COLUMN_NAME=a.COLUMN_NAME
ORDER BY tbName
---------------------------------------------------以上是oracle------------------------------------------------------------
SELECT
(case ORDINAL_POSITION when 1 then TABLE_NAME ELSE '' end ) '库名',
ORDINAL_POSITION AS '列的排列顺序',
COLUMN_COMMENT AS '注释',
COLUMN_NAME AS '列名',
IS_NULLABLE AS '是否为空',
DATA_TYPE AS '数据类型',
CHARACTER_MAXIMUM_LENGTH AS '字符最大长度',
COLUMN_DEFAULT AS '默认值',
NUMERIC_PRECISION AS '数值精度(最大位数)',
NUMERIC_SCALE AS '小数精度',
COLUMN_TYPE AS 列类型,
COLUMN_KEY 'KEY',
EXTRA AS '额外说明'
FROM
information_schema.`COLUMNS`
WHERE
TABLE_SCHEMA = 'ceshi' (ceshi替换为库名即可)
ORDER BY
TABLE_NAME,
ORDINAL_POSITION;
---------------------------------------------------以上是mysql------------------------------------------------------------