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