前言:
而今朋友们对“mssql查询表字段”大约比较注重,大家都需要分析一些“mssql查询表字段”的相关知识。那么小编同时在网摘上网罗了一些关于“mssql查询表字段””的相关内容,希望咱们能喜欢,看官们一起来学习一下吧!1.通过创建一个函数来获取表字段信息
create function [dbo].[F_TableViewDescription]( @tableName nvarchar(100)--表名)returns tablereturn(select TableName=(case when b.colorder=1 then a.name else '' end),TableMemo=( case when b.colorder=1 then c.value else '' end),b.colid as indexs,b.name as ColumnName,IsIdentity=case when COLUMNPROPERTY( b.id,b.name,'IsIdentity')=1 then '√'else '' end,IsPrimaryKey=case when exists(select 1 from sys.sysobjects where xtype='PK' and parent_obj=b.id and name in(select name from sys.sysindexes where indid in(select indid from sys.sysindexkeys where id=b.id and colid=b.colid))) then '√' else '' end,TypeName=d.name,ByteLength=( case when b.length=-1 then 'max' else CONVERT(varchar(50),b.length) end),ColumnLength=( case when COLUMNPROPERTY(b.id,b.name,'Precision')=-1 then 'max' else CONVERT(varchar(50),COLUMNPROPERTY(b.id,b.name,'Precision')) end),IsNull=case when COLUMNPROPERTY(b.id,b.name,'AllowsNull')=1 then '√' else '' end,Scale=Convert(varchar(20),isnull(COLUMNPROPERTY(b.id,b.name,'Scale'),0)),DefaultValue=e.text,ColumnMemo=isnull(f.value,'') from sys.sysobjects a inner join sys.syscolumns b on a.id=b.id and a.xtype='U' and a.name<>'dtproperties' left join sys.extended_properties c on a.id=c.major_id and c.minor_id=0left join sys.systypes d on b.xusertype=d.xusertypeleft join sys.syscomments e on e.id=b.cdefaultleft join sys.extended_properties f on b.id=f.major_id and b.colid=f.minor_id where a.name=ltrim(rtrim(isnull(@tableName,''))) --order by b.colid)
2.使用如下所示
select * from F_TableViewDescription('表名')
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #mssql查询表字段