国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

蛙蛙推薦:怎樣獲取一個表中所有字段的信息

2024-07-21 02:06:27
字體:
來源:轉載
供稿:網友

先創建一個視圖

create view fielddesc   
as
select o.name as table_name,c.name as field_name,t.name as type,c.length as

length,c.isnullable as isnullable,convert(varchar(30),p.value) as desp
from syscolumns c 
join systypes t on c.xtype = t.xusertype
join sysobjects o on o.id=c.id
left join    sysproperties p on p.smallid=c.colid and p.id=o.id   
where o.xtype='u'

查詢時:
select * from fielddesc where table_name = '你的表名'

還有個更強的語句,是鄒建寫的,也寫出來吧

select
 (case when a.colorder=1 then d.name else '' end) n'表名',
 a.colorder n'字段序號',
 a.name n'字段名',
 (case when columnproperty( a.id,a.name,'isidentity')=1 then '√'else '' end) n'標識',
 (case when (select count(*)
 from sysobjects
 where (name in
           (select name
          from sysindexes
          where (id = a.id) and (indid in
                    (select indid
                   from sysindexkeys
                   where (id = a.id) and (colid in
                             (select colid
                            from syscolumns
                            where (id = a.id) and (name = a.name))))))) and
        (xtype = 'pk'))>0 then '√' else '' end) n'主鍵',
 b.name n'類型',
 a.length n'占用字節數',
 columnproperty(a.id,a.name,'precision') as n'長度',
 isnull(columnproperty(a.id,a.name,'scale'),0) as n'小數位數',
 (case when a.isnullable=1 then '√'else '' end) n'允許空',
 isnull(e.text,'') n'默認值',
 isnull(g.[value],'') as n'字段說明'
--into ##tx

from  syscolumns  a left join systypes b
on  a.xtype=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 sysproperties g
on a.id=g.id and a.colid = g.smallid 
order by object_name(a.id),a.colorder
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黎平县| 沽源县| 浮山县| 沙河市| 赫章县| 苏州市| 图片| 淳安县| 汕尾市| 祥云县| 武川县| 措美县| 平塘县| 随州市| 三穗县| 诸城市| 怀来县| 阳朔县| 太仆寺旗| 辽阳县| 惠水县| 敦煌市| 萍乡市| 贡嘎县| 怀来县| 长治市| 曲阜市| 花莲县| 启东市| 射阳县| 河池市| 淮阳县| 安义县| 淮滨县| 拉萨市| 高邮市| 新津县| 静乐县| 鄄城县| 垫江县| 介休市|