先建立乙個檢視
create view fielddesc
asselect 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.**allid=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.**allid
order by object_name(a.id),a.colorder
wan
怎樣獲取乙個表中所有欄位的資訊
先建立乙個檢視 create view fielddesc asselect o.name as table name,c.name as field name,t.name as type,c.length as length,c.isnullable as isnullable,convert ...
怎樣獲取乙個表中所有欄位的資訊
先建立乙個檢視 create view fielddesc asselect o.name as table name,c.name as field name,t.name as type,c.length as length,c.isnullable as isnullable,convert ...
蛙蛙推薦 怎樣獲取乙個表中所有欄位的資訊
先建立乙個檢視 create view fielddesc asselect o.name as table name,c.name as field name,t.name as type,c.length as length,c.isnullable as isnullable,convert ...