create PROCEDURE [dbo].[GettableExplain]
@tablename varchar(100)
AS
SELECT
表名 = Case When A.colorder=1 Then D.name Else '--'+D.name 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,'PRECISION'),
小数位数 = isnull(ColUMNPROPERTY(A.ID,'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=@TABLENAME --如果只查询指定表,加上此条件 Order By A.ID,A.colorder
以上是内存溢出为你收集整理的sqlserver获取数据库表结构的存储过程全部内容,希望文章能够帮你解决sqlserver获取数据库表结构的存储过程所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)