取得sql2005 表字段資訊的sql語句

2021-05-12 07:17:09 字數 1624 閱讀 9233

select     row_number() over (order by id) as row_number, fieldname, fielddescn as cnname, fieldtype, fieldlength, isidentifier, iskeyfield, allownull, defaultvalue, 

fielddescn

from         (select     top 100 a.id, d .name n'tablename', a.colorder n'fieldnumber', a.name n'fieldname', (case when columnproperty(a.id, a.name, 'isidentity') 

= 1 then '○' else ' ' end) n'isidentifier', (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'iskeyfield', 

b.name n'fieldtype', a.length n'fieldsize', columnproperty(a.id, a.name, 'precision') as n'fieldlength', isnull(columnproperty(a.id, a.name, 

'scale'), 0) as n'decimaldigits', (case when a.isnullable = 1 then ' ' else '○' end) n'allownull', isnull(e.text, '') n'defaultvalue', isnull(g.[value], '') 

as n'fielddescn'

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

sys.extended_properties g on a.id = g.major_id and a.colid = g.minor_id

order by object_name(a.id), a.colorder) ttt

SQL2005 取得行號

下面介紹乙個sql server 2005 中的新東東 row number 返回結果集分割槽內行的序列號,每個分割槽的第一行從 1 開始。語法 row number over 備註 order by 子句可確定在特定分割槽中為行分配唯一 row number 的順序。引數 將 from 子句生成的...

sql2005多欄位模糊查詢

create proc getlikesql colvalue varchar 30 asdeclare colcount int declare tbname varchar 50 declare sql varchar 8000 declare i int set i 1 select colc...

查詢表字段屬性資訊SQL

select 表名 case when a.colorder 1 then d.name else end,表說明 case when a.colorder 1 then isnull f.value,else end,字段序號 a.colorder,欄位名 a.name,標識 case when ...