获取数据库表的字段信息
SELECT
表名 = Case When A.colorder=1 Then D.name Else '' End,
表说明 = Case When A.colorder=1 Then isnull(F.value,'') Else '' End,
字段序号 = A.colorder,
字段名 = A.name,
字段说明 = isnull(G.[value],''),
标识 = 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,'')
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
--where d.name='OrderInfo' --如果只查询指定表,加上此条件
Order By
A.id,A.colorder
//mysql
SELECT
TABLE_NAME,
column_name,
DATA_TYPE,
column_comment,
(case when COLUMN_KEY='PRI' then 1 else 0 end) as IsPK,
(case when IS_NULLABLE = 'NO' then 0 else 1 end)as CanNull
FROM
information_schema. COLUMNS
WHERE
TABLE_SCHEMA = '数据库';
再将结果复制到excel中,修改为自己需要的样子。
【获取数据库表的字段信息】转载于:https://www.cnblogs.com/joyandjoys/p/10889290.html
推荐阅读
- 急于表达——往往欲速则不达
- Docker应用:容器间通信与Mariadb数据库主从复制
- 关于QueryWrapper|关于QueryWrapper,实现MybatisPlus多表关联查询方式
- mybatisplus如何在xml的连表查询中使用queryWrapper
- leetcode|leetcode 92. 反转链表 II
- 下雪了,飞去你的城市拥抱你|下雪了,飞去你的城市拥抱你 | 有个直男向我表白了
- 2019女表什么牌子好(如何挑选女士手表?)
- Python爬虫|Python爬虫 --- 1.4 正则表达式(re库)
- 数据库设计与优化
- 佳琪(三十一)