久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

sp_MSforeachdb 查詢幫助

sp_MSforeachdb query help(sp_MSforeachdb 查詢幫助)
本文介紹了sp_MSforeachdb 查詢幫助的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在使用許多相同的數(shù)據(jù)庫,因此我使用 sp_MSforeachdb 過程以便我可以從表中檢索信息.

I'm working with a lot of databases that are the same so I am using the sp_MSforeachdb procedure so that I can retrieve information from a table.

我遇到的問題是盒子上還有其他數(shù)據(jù)庫沒有表,所以我拋出了無效對象錯誤.

The problem I have encountered is that there are other databases on the box that don't have the table, so I'm throwing invalid object errors.

這是我目前所擁有的,我正在過濾 LoginDatabase,因為它具有相同的表,但我不希望在查詢中使用它.

Here is What I have at the moment, I'm filtering LoginDatabase because it has the same table but I don't want that in the query.

我的問題是,我如何才能將其限制為包含我想從中獲取信息的表的數(shù)據(jù)庫.

My question is, how can I restrict it just to the databases with the table I want to get information back from.

SET NOCOUNT ON

CREATE TABLE #tmpData
(
    DbName VARCHAR(30),
    DbVersion FLOAT
)

exec sp_msforeachdb @command1='
    USE ?;

    INSERT INTO #tmpData
    SELECT ''?'', (SELECT Setting 
        FROM ?.dbo.gl_SysParams 
        WHERE Keyword = ''DatabaseSchema'')
    FROM sysobjects o
    WHERE type=''U'' 
    AND [name] = ''gl_SysParams'' 
    AND ''?'' <> ''LoginDatabase'' ORDER BY [name]
    '   

SET NOCOUNT OFF

SELECT DbName, DbVersion FROM #tmpData ORDER BY DbName

DROP TABLE #tmpData

推薦答案

您可以在每個數(shù)據(jù)庫中使用對 sp_MSforeachtable 的調(diào)用,您可以在其中使用 @WhereAnd 參數(shù)過濾到您感興趣的表 - 它贏了'不存在于您不感興趣的數(shù)據(jù)庫中,因此 sp_MSforeachtable 將在其中運行 0 次,并在每個帶有該表的數(shù)據(jù)庫中運行 1 次.

You could use a call to sp_MSforeachtable within each database, where you use the @WhereAnd parameter to filter down to just the table you're interested in - it won't exist in the database you're not interested in, so sp_MSforeachtable will run 0 times in there, and 1 time in each database with the table.

編輯簡單的例子只是在我的一個隨機服務(wù)器上運行,我知道只有一個數(shù)據(jù)庫有一個 tblClient 表,有一個 ClientID 列(請原諒命名):

Edit Simple example just run against a random server of mine, where I knew only one database had a tblClient table, with a ClientID column (forgive the naming):

create table #t (
    ID int not null
)
exec sp_MSforeachdb 'use ? exec sp_MSforeachtable ''insert into #t(ID) select ClientID from ~'',''~'',@whereand=''and o.name=''''tblClient''''''','?'
select * from #t
drop table #t

這篇關(guān)于sp_MSforeachdb 查詢幫助的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Modify Existing decimal places info(修改現(xiàn)有小數(shù)位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關(guān)名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復(fù)項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關(guān)系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 午夜激情国产 | 在线国产视频 | 999热精品视频 | 观看av| 亚洲成人高清 | 亚洲国产精品99久久久久久久久 | 欧美综合一区二区三区 | av一区二区三区四区 | 精品久久久久久久久久 | 久久久精品综合 | 欧美色影院| 亚洲精品在| 九九热国产视频 | 成人av影院 | 天天躁日日躁狠狠躁2018小说 | 在线观看国产 | 中文字幕 国产 | 欧美黄色片| 超碰欧美 | 亚洲精品视频在线 | 亚洲草草视频 | 成人国产精品久久 | 中文字幕乱码亚洲精品一区 | 国产日产精品一区二区三区四区 | 亚洲美女一区二区三区 | 亚洲国产成人久久久 | 国产色网站 | 视频在线h | 亚洲三区视频 | 欧美性一区二区三区 | 亚洲国产精品久久久 | 亚洲不卡视频 | 久久久精品一区二区 | 波多野结衣一区二区三区在线观看 | 日韩电影免费观看中文字幕 | 男女羞羞的网站 | h视频在线免费观看 | 国产激情一区二区三区 | 99热免费在线 | 免费99视频 | 国产不卡在线观看 |