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

sp_MSforeachdb 查詢幫助

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

問題描述

我正在使用許多相同的數據庫,因此我使用 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.

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

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.

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

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

推薦答案

您可以在每個數據庫中使用對 sp_MSforeachtable 的調用,您可以在其中使用 @WhereAnd 參數過濾到您感興趣的表 - 它贏了'不存在于您不感興趣的數據庫中,因此 sp_MSforeachtable 將在其中運行 0 次,并在每個帶有該表的數據庫中運行 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.

編輯簡單的例子只是在我的一個隨機服務器上運行,我知道只有一個數據庫有一個 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

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

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

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 中文字幕中文字幕 | 久久亚洲综合 | 久久久精品网站 | 亚州成人| 综合色久 | 久艹网站 | 香蕉一区 | 日韩中文一区 | 精品久久香蕉国产线看观看亚洲 | 成人免费观看视频 | 一级毛片在线看 | 日批av| 最近日韩中文字幕 | 亚洲国产精品久久久久婷婷老年 | 午夜资源| 日韩精品一区在线观看 | 成人精品鲁一区一区二区 | 99热精品在线 | 成人免费黄色 | 亚洲欧美国产精品久久 | 一区二区欧美在线 | 中文字幕精品视频在线观看 | 久久久综合网 | 一级毛片免费视频观看 | 亚洲第一女人av | 午夜久久久 | 国产四虎 | 爱操av| 国产观看 | 欧美日韩一区二区在线 | 在线看一区二区 | 国产精品久久久久永久免费观看 | 国产九九av | 2一3sex性hd| 精品国产乱码一区二区三 | 一级欧美视频 | 亚洲欧美综合精品另类天天更新 | 草久网 | 日本精品一区二区三区在线观看视频 | 91精品国产91久久久久游泳池 | 成人日b视频 |