欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

sql根据表名获取字段及对应说明

程序员文章站 2023-12-16 14:01:58
复制代码 代码如下: select tablename = object_name(c.object_id), columnsname = c.name, descript...
复制代码 代码如下:

select
tablename = object_name(c.object_id),
columnsname = c.name,
description = ex.value,
columntype=t.name,
length=c.max_length
from
sys.columns c
left outer join
sys.extended_properties ex
on
ex.major_id = c.object_id
and ex.minor_id = c.column_id
and ex.name = 'ms_description'
left outer join
systypes t
on c.system_type_id=t.xtype
where
objectproperty(c.object_id, 'ismsshipped')=0
and object_name(c.object_id) ='tablename'



1.获取所有数据库名:
select name from master..sysdatabases order by name
2.获取所有表名:
select name from databasename..sysobjects where xtype='u' order by name
xtype='u':表示所有用户表;
xtype='s':表示所有系统表;
3.获取所有字段名:
select name from syscolumns where id=object_id('tablename')

上一篇:

下一篇: