您的位置 首页 > 数码极客

sqll如何获得表格字段如何在表格中添加字段

1.通过创建一个函数来获取表字段信息

create function [dbo].[F_TableViewDescription] ( @tableName nvarchar(100)--表名 ) returns table return( 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 where xtype='PK' and parent_obj=b.id and name in( select name from where indid in(select indid from 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;Precision')=-1 then 'max' else CONVERT(varchar(50),COLUMNPROPERTY;Precision')) end), IsNull=case when COLUMNPROPERTY;AllowsNull')=1 then '√' else '' end, Scale=Convert(varchar(20),isnull(COLUMNPROPERTY;Scale'),0)), DefaultValue=e.text, ColumnMemo=isnull;') from a inner join b on a.id=b.id and a.xtype='U' and a.name<>'dtproperties' left join c on a.id=c.major_id and c.minor_id=0 left join d on b.xusertype=d.xusertype left join e on e.id=b.cdefault left join 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('表名')

责任编辑: 鲁达

1.内容基于多重复合算法人工智能语言模型创作,旨在以深度学习研究为目的传播信息知识,内容观点与本网站无关,反馈举报请
2.仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证;
3.本站属于非营利性站点无毒无广告,请读者放心使用!

“sqll如何获得表格字段,如何在表格中添加字段,表格的字段如何设置”边界阅读