sqlserver數(shù)據(jù)庫介紹詳細(xì) 判斷sql server中的某個數(shù)據(jù)庫是否存在?
在編寫SQL 經(jīng)常需要判斷一個數(shù)據(jù)庫是否已經(jīng)存在,如果不存在,就創(chuàng)建這個數(shù)據(jù)庫。常用的方法有三種:1。select * from where name # 39 test _ DB # 39如果沒有查
在編寫SQL 經(jīng)常需要判斷一個數(shù)據(jù)庫是否已經(jīng)存在,如果不存在,就創(chuàng)建這個數(shù)據(jù)庫。常用的方法有三種:1。select * from where name # 39 test _ DB # 39如果沒有查詢結(jié)果,則name所代表的數(shù)據(jù)庫不存在。2.object_id(#39test_db#39)如果無法獲得對象ID(null),則該對象不存在;通常在object _ ID (# 39test _ db # 39)為null或If(select object _ ID(# 39 test _ db # 39))為null時使用3.db _ id (# 39test _ db # 39)如果無法獲得數(shù)據(jù)庫ID,則由名稱指示的數(shù)據(jù)庫不存在。事實上,這個方法也在sysdatabases中查找并返回數(shù)據(jù)庫的ID。如果db_id(#39test_db#39)為空,或者如果(select db _ id (# 39t