select
(case when a.colorder=1 then d.name else '' end) as 表名,
a.colorder as 字段序號,
a.name as 欄位名,
(case when columnproperty(a.id,a.name,'isidentity')=1 then '√' else '' end) as 標識,
(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) as 主鍵,
b.name as 型別,
a.length as 占用位元組數,
columnproperty(a.id,a.name,'precision') as 長度,
isnull(columnproperty(a.id,a.name,'scale'),0) as 小數字數,
(case when a.isnullable=1 then '√' else '' end) as 允許空,
isnull(e.text,'') as 預設值,
isnull(g.[value],'') as 字段說明
from syscolumns a
left join systypes b on a.xtype=b.usertype
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
where d.name='com_sequence'
order by a.id,a.colorder
上面的比較複雜,下面是簡化過的
select
(case when a.colorder=1 then d.name else '' end) as tablename,
a.name as fieldname,
isnull(g.[value],'') as fielddes
from syscolumns a
inner join sysobjects d on a.id=d.id and d.xtype='u' and d.name<>'dtproperties'
left join sys.extended_properties g on a.id=g.major_id and a.colid =g.minor_id
--where d.name='' --要查詢的表
order by a.id,a.colorder
SQLSERVER 2005 遞迴查詢
專案中有使用者組表usergroup如下 其中pid表示當前組的上級組 表資料如下 現在想查詢出頂級組 沒有上級組叫頂級組 a1組的所有子孫組id,sql如下 查詢子節點 with rtd1 as select id pid from usergroup rtd2 as select from rt...
SQLSERVER 2005 遞迴查詢
專案中有使用者組表usergroup如下 其中pid表示當前組的上級組 表資料如下 現在想查詢出頂級組 沒有上級組叫頂級組 a1組的所有子孫組id,sql如下 查詢子節點 with rtd1 as select id pid from usergroup rtd2 as select from rt...
SQL SERVER 2005 遠端查詢
在從事開發工作時一些比較大的專案會使用到多個資料庫,在寫檢視和儲存過程時常會用到遠端查詢,下面著重介紹一下在sql2005下如何通過建立鏈結伺服器,使sql可以對遠端的sql伺服器或oracle伺服器進行遠端查詢 一.建立sql到sql的遠端查詢 1.新增鏈結伺服器 exec sp addlinke...