查詢某個庫里所有表的定義,包括欄位名,值型別,長度,是否為空,是否為主鍵等
select
sysobjects.name
astb_name, syscolumns.name
ascol_name
, systypes.name
ascol_type, syscolumns.length
ascol_len,
isnull
(sysproperties.value,syscolumns.name)
ascol_memo,
case
when
syscolumns.name
in(select'主鍵
'=a.name
from
syscolumns a
inner
join
sysobjects b
ona.id
=b.id
andb.xtype='
u'andb.name
<>
'dtproperties
'where
exists
(select
1from
sysobjects
where
xtype='
pk'andname
in(select
name
from
sysindexes
where
indid
in(select
indid
from
sysindexkeys
where
id =
a.id
andcolid
=a.colid))
) andb.name
=sysobjects.name)
then
1else
0end
asis_key
from
sysobjects,systypes,syscolumns
left
join
sysproperties
on(syscolumns.id
=sysproperties.id
andsyscolumns.colid
=sysproperties.**allid)
where
(sysobjects.xtype ='
u'orsysobjects.xtype ='
v')
andsysobjects.id
=syscolumns.id
andsystypes.xtype
=syscolumns.xtype
andsystypes.name
<>
'sysname
'and
sysobjects.name
like'%
'order
bysysobjects.name, syscolumns.colid
將最後乙個「%」號改為某個資料表名,即是檢視該錶的定義
sql 獲取表結構
alter procedure dbo tbinfo tbname varchar 50 表名稱 as select 表名 case when a.colorder 1 then d.name else end,表說明 case when a.colorder 1 then isnull f.val...
SQL之表定義
sql 結構化查詢語言 1 用create table命令定義sql關係 create table r a1 d1,a2 d2,an dn,完整性約束1 完整性約束k 其中,r是關係名,每個ai是關係r模式中的乙個屬性名,di是屬性ai的域 2 完整性約束 not null,乙個屬性上的not nu...
sql 查詢表定義
1 2alter proc dbo test querytableinfo 3 4 tablename varchar 200 5 6as 7begin 8select 9 表名 case when a.colorder 1then d.name else end 10 表說明 case when ...