獲取表的字段資訊

2021-06-02 11:11:54 字數 1136 閱讀 3494

select 

表名=case when a.colorder=1 then d.name else '' end, 

欄位名=a.name, 

標識=case when columnproperty(a.id,a.name,'isidentity')=1 then 'true' else 'false' 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 'true' else 'false' end, 

型別=b.name, 

占用位元組數=a.length, 

長度=columnproperty(a.id,a.name, 'precision'), 

小數字數=isnull(columnproperty(a.id,a.name, 'scale'),0), 

允許空=case when a.isnullable=1 then 'true'else 'false' end, 

預設值=isnull(e.text, ''), 

字段說明=isnull(g.[value], '') 

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' or d.xtype='v') and d.name <> 'dtproperties' and d.name = 'fieldtable'

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 and g.name='ms_description'

order by a.id,a.colorder

獲取oracle表結構的字段資訊

select a.column id as 列號,a.column name as 列名,a.data type as 型別,decode a.data type,number a.data precision,a.data length as 長度,a.data scale as 小數字,deco...

根據表名獲取表字段資訊

實際應用中不免需要調取資料庫表字段的相關資訊,特此將 貼出,以作備用,調取的資訊 欄位名 字段型別 字段長度 是否主鍵 說明 建立sqlparameter public class cp public sqldbtype coltype public int collength public boo...

PostgreSQL獲取所有的表資訊 字段資訊

獲取資料庫中所有table名 select tablename from pg tables where tablename not like pg and tablename not like sql order by tablename 獲取資料庫中所有table名及table的註解資訊 sel...