sql server中如何判斷表或者數(shù)據(jù)庫的存在,但在實(shí)際使用中,需判斷Status狀態(tài)位:
其中某些狀態(tài)位可由用戶使用 sp_dboption(read only、dbo use only、single user 等)進(jìn)行設(shè)置:
1 = autoclose;使用 sp_dboption 設(shè)置。 數(shù)據(jù)庫完全關(guān)閉,其資源在最后一個(gè)用戶注銷后釋放。
4 = select into/bulkcopy;使用 sp_dboption 設(shè)置。允許使用 Select INTO 語句和快速大容量復(fù)制。
8 = trunc. log on chkpt;使用 sp_dboption 設(shè)置。如果數(shù)據(jù)庫處于日志截?cái)嗄J?,則檢查點(diǎn)將截?cái)嗳罩局蟹腔顒?dòng)的部分。只能為 master 數(shù)據(jù)庫設(shè)置此選項(xiàng)。16 = torn page detection,使用 sp_dboption 設(shè)置。可以檢測(cè)殘缺頁。
32 = loading。
64 = pre recovery。
128 = recovering。
256 = not recovered。
512 = offline;使用sp_dboption 設(shè)置。數(shù)據(jù)庫將處于脫機(jī)狀態(tài)。
1024 = read only;使用 sp_dboption 設(shè)置。用戶僅能讀取數(shù)據(jù)庫中的數(shù)據(jù)而無法對(duì)其進(jìn)行修改。
2048 = dbo use only;使用sp_dboption 設(shè)置。只有數(shù)據(jù)庫所有者可以使用數(shù)據(jù)庫。
4096 = single user;使用 sp_dboption 設(shè)置。每次只能有一個(gè)用戶訪問數(shù)據(jù)庫。
32768 = emergency mode。
4194304 = autoshrink。
1073741824 = cleanly shutdown。
可以同時(shí)打開多個(gè)位。
譬如:判斷一個(gè)數(shù)據(jù)庫是否offline
select * From master.dbo.sysdatabases where name='pubs' and status>512
SQL Server中判斷表對(duì)象是否存在:
select count(*) from sysobjects where id = object_id('數(shù)據(jù)庫名.Owner.表名')
if exists
(select count(*) from sysobjects where id = object_id('數(shù)據(jù)庫名.Owner.表名'))
print '存在'
else
print '不存在'
SQL Server中判斷表中字段是否存在:
if exists(select * from syscolumns where name='colname1' and id=object_id('數(shù)據(jù)庫名.Owner.表名'))
print '存在'
else
print '不存在'
代表表tablename1中存在colname1字段
例:
select * from syscolumns where name='Test' and id=object_id('dbo.test')
Access中判斷表對(duì)象是否存在:
其實(shí),Access數(shù)據(jù)庫也有系統(tǒng)表,存放有對(duì)象名
Select Count(*) AS Qty FROM MSysObjects Where ((MSysObjects.Name) Like '表名');
標(biāo)簽:呼和浩特 江蘇 重慶 貴州 昭通 上海 拉薩 新鄉(xiāng)
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《sqlserver 各種判斷是否存在(表名、函數(shù)、存儲(chǔ)過程等)》,本文關(guān)鍵詞 sqlserver,各種,判斷,是否,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。