詳細資訊參照
sql2005
sql code
go--2005實現資料庫表字段屬性統計(2000裡的系統表sysproperties描述表不存在,2005裡用sys.extended_properties檢視替代)
select[表名
]=c.name,
[表說明]=
isnull
(f.[
value],
''),
[列名]=
a.name,
[列序號]=
a.column_id,
[標識]=
case
when
is_identity=1
then'√
'else
''end
, [主鍵
]=case
when
exists
(select
1from
sys.objects x
join
sys.indexes y
onx.type=n
'pk'and
x.name
=y.name
join
sysindexkeys z
onz.id=a.
object_id
andz.indid
=y.index_id
andz.colid
=a.column_id)
then'√
'else
''end
, [型別
]=b.name,
[位元組數]=
case
whena.[
max_length]=-
1and
b.name!='
xml'
then
'max/2g
'when
b.name='
xml'
then
'2^31-1位元組/2g
'else
rtrim
(a.[
max_length])
end,
[長度]=
case
when
columnproperty
(a.object_id
,a.name,
'precision')
=-1then
'2^31-1
'else
rtrim
(columnproperty
(a.object_id
,a.name,
'precision
'))
end,
[小數]=
isnull
(columnproperty
(a.object_id
,a.name,
'scale'),
0),[是否為空]=
case
when
a.is_nullable=1
then'√
'else
''end
,
[列說明]=
isnull
(e.[
value],
''),
[預設值]=
isnull
(d.text,''
)
from
sys.columns a
left
join
sys.types b
ona.user_type_id
=b.user_type_id
inner
join
sys.objects c
ona.
object_id=c.
object_id
andc.type='
u'left
join
syscomments d
ona.default_object_id
=d.id
left
join
sys.extended_properties e
one.major_id=c.
object_id
ande.minor_id
=a.column_id
ande.class=1
left
join
sys.extended_properties f
onf.major_id=c.
object_id
andf.minor_id=0
andf.class=1
sql2000:
sql code
elect表名
=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
columnproperty
( a.id,a.name,
'isidentity')
=1then'√
'else
''end
, 主鍵
=case
when
exists
(select
1from
sysobjects
where
xtype='
pk'andparent_obj
=a.id
andname in(
select
name
from
sysindexes
where
indid in(
select
indid
from
sysindexkeys
where
id =
a.id
andcolid
=a.colid)))
then'√
'else
''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'√
'else
''end
, 預設值
=isnull
(e.text,''
), 字段說明
=isnull
(g.[
value],
'')from
syscolumns a
left
join
systypes b
ona.xusertype
=b.xusertype
inner
join
sysobjects d
ona.id
=d.id
andd.xtype='
u'andd.name
<>
'dtproperties
'left
join
syscomments e
ona.cdefault
=e.id
left
join
sysproperties g
ona.id
=g.id
anda.colid
=g.smallid
left
join
sysproperties f
ond.id
=f.id
andf.smallid=0
where
d.name='
要查詢的表'--
如果只查詢指定表,加上此條件
order
bya.id,a.colorder
全資料庫各表中查詢內容所在的字段位置
declare str varchar 100 set str ph 要搜尋的字串 declare s varchar 8000 declare tb cursor local for select s if exists select 1 from b.name where a.name like...
資料庫 SQLServer中預設表有哪些
sql server安裝4個系統資料庫。它們分別是master資料庫 model資料庫 tempdb資料庫和msdb資料庫。這些資料庫是sql server的心臟和靈魂。另外,還安裝了兩個例項資料庫,分別是 northwind和pubs 系統資料庫4個 master資料庫 master資料庫控制sq...
mysql資料庫鎖有哪些 資料庫常用的鎖有哪些
一 資料庫為什麼需要鎖?為了保證資料的一致性。mysql資料庫存在多種資料引擎,mysql各儲存引擎使用了三種型別 級別 的鎖定機制 表級鎖定,行級鎖定和頁級鎖定。二 表級鎖 1.表級鎖 表級鎖一次會將整個表鎖定,所可以很好的避免死鎖問題 1 鎖定粒度大,鎖衝突概率高 併發度低 2 好處是不會出現死...