我正在尋找一個查詢,它將從所有數據庫中返回結果,但只有表存在的位置。從表中存在的所有數據庫中選擇查詢
我已經運行EXEC sp_MsForEachDb @command1 = 'select * from ?.dbo.users'
但這帶回了很多錯誤,因此隱藏了數據庫確實具有這些表
我正在尋找一個查詢,它將從所有數據庫中返回結果,但只有表存在的位置。從表中存在的所有數據庫中選擇查詢
我已經運行EXEC sp_MsForEachDb @command1 = 'select * from ?.dbo.users'
但這帶回了很多錯誤,因此隱藏了數據庫確實具有這些表
`EXEC sp_MsForEachDb @command1 =
' use ?; if exists(select * from information_schema.tables where table_`name=''test'')begin select * from test end'
上面的語句會隱藏所有錯誤的結果,因爲它會檢查是否存在表第一..
也可以排除系統數據庫如..
EXEC sp_MsForEachDb @command1 = ' use ?; if db_id()<=4 return if exists(select * from information_schema.tables where table_name=''test'')begin select * from test end'
能否請您發佈這些錯誤爲好,這將有助於... – Aditya
重複的[這](HTTP感謝://計算器.COM /問題/ 20131930/SP-msforeachdb只,包括-結果從 - 數據庫與 - 結果)? – JohnHC