基本信息
源码名称:获取表结构和详细说明的函数
源码大小:1.64KB
文件格式:.sql
开发语言:SQL
更新时间:2020-03-30
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

方便快捷的sql自定义函数,能迅速明了的查看表结构


SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
GO


CREATE FUNCTION [dbo].[TableInfor](
@tablename NVARCHAR(50)
)
RETURNS TABLE 
AS
RETURN     
(
SELECT 字段名 = 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 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') ,
      允许空 = 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
where d.name=@tablename --需要查询的表名
--order by a.id,a.colorder
)
GO