1select
2 (case
when a.colorder=
1then d.name else
''end) as 表名,--
如果表名相同就返回空 syscolumns(表字段資訊表) a sysobjects d
3 a.colorder as
字段序號,
4 a.name as
欄位名,
5 (case
when
columnproperty( a.id,a.name, '
isidentity
' )=
1then'√
'else
''end) as 標識, --
返回isidentity的值,isidentity只有兩個值:0、1
6 (case
when (select
count(*) from sysobjects--
查詢主鍵
7where (name in
8 (select name from
sysindexes
9where (id = a.id) and (indid in
10 (select indid from
sysindexkeys
11where (id = a.id) and (colid in
12 (select colid from
syscolumns
13where (id = a.id) and (name =
a.name))
14)))))
15and (xtype ='pk
' ))>
0then'√
'else
''end) as 主鍵,--
查詢主鍵end
16 b.name as 型別, --
systypes b
17 a.length as
占用位元組數,
18columnproperty(a.id,a.name,'
precision
' ) as
長度,
19isnull(columnproperty(a.id,a.name,'
scale
' ),0) as
小數字數,
20 (case
when a.isnullable=
1then'√
'else
''end) as
允許空,
21isnull(e.text,'' ) as 預設值, --
syscomments e
22isnull(g.[
value
],'' ) as 字段說明 --
sys.extended_properties g (字段資訊表)
23from syscolumns a left
join
systypes b
24on a.xtype=
b.xusertype
25inner
join
sysobjects d
26on a.id=d.id and d.xtype='u
'and d.name<>
'dtproperties'27
left
join
syscomments e
28on a.cdefault=
e.id
29left
join
sys.extended_properties g
30on a.id=g.major_id and a.colid =
g.minor_id
31where d.name=
'systempara'--
所要查詢的表
32order
by a.id,a.colorder
SQL2005遞迴查詢語法
create table code catalog structure catalogid nvarchar 10 col varchar 10 parentid nvarchar 10 insert into code catalog structure select 我是一層的一 aaa roo...
sql2005 的樹形遞迴查詢
在sqlserver中從2005開始支援樹形遞迴查詢,其方法如下 從給定的根節點 可以是多個 向下查詢,直到所有子節點 with myt2 as select from 表名 where 根節點查詢條件 union all select 表名.from myt2 inner join 表名 on m...
sql2005表的基本操作
use caowen exec sp help dep 這是檢視資料庫表的結構 select from sysfiles 這是檢視資料庫檔案 這是修改資料庫檔案 alter database caowen modify file name caowenndf1 size 65mb 這裡指定的檔案的大...