sp-msforeachdb

How can I omit system databases and allow SQL Server 2008 agent job to move past ERROR_NUMBER 208?

孤街醉人 提交于 2019-12-13 03:56:07
问题 I have created a SQL Server 2008 Agent job that runs against all databases on the server. I am using the undocumented MS procedure, sp_MSforEachDB . I am specifying only certain databases to be processed and when these databases are found, if ERROR_NUMBER = 208 , I want a table to be created and processing to continue to the next database. I also want to omit the system databases so the tabel doesn't get created in a system database. I though by specifying the names of the databases I want to

sp_MSforeachdb query help

南楼画角 提交于 2019-12-11 16:40:01
问题 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. 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

Help with sp_msforeachdb -like queries

我的梦境 提交于 2019-12-11 06:36:26
问题 Where I'm at we have a software package running on a mainframe system. The mainframe makes a nightly dump into sql server, such that each of our clients has it's own database in the server. There are a few other databases in the server instance as well, plus some older client dbs with no data. We often need to run reports or check data across all clients. I would like to be able to run queries using sp_msforeachdb or something similar, but I'm not sure how I can go about filtering unwanted

SQL Iterate Over All Tables

风流意气都作罢 提交于 2019-12-02 07:12:06
问题 I am running the following code to extract all relevant rows from all tables that have a particular column. The outer IF is supposed to check if the column exists on the table for that iteration. If not, it should finish that iteration and move to the next table. If the table has the GCRecord column, it should then check to see if that table will return any records. If there are no records to return, it should end that iteration and move on to the next table. If there are records, it should

SQL Iterate Over All Tables

巧了我就是萌 提交于 2019-12-02 04:19:39
I am running the following code to extract all relevant rows from all tables that have a particular column. The outer IF is supposed to check if the column exists on the table for that iteration. If not, it should finish that iteration and move to the next table. If the table has the GCRecord column, it should then check to see if that table will return any records. If there are no records to return, it should end that iteration and move on to the next table. If there are records, it should display them in SSMS. USE WS_Live EXECUTE sp_MSforeachtable ' USE WS_Live IF EXISTS( SELECT * FROM sys

Execute “sp_msforeachdb” in a Java application

不羁的心 提交于 2019-11-28 01:38:45
Hi StackOverflow community :) I come to you to share one of my problems... I have to extract a list of every table in each database of a SQL Server instance , I found this query : EXEC sp_msforeachdb 'Use ?; SELECT DB_NAME() AS DB, * FROM sys.tables' It works perfectly on Microsoft SQL Server Management Studio but when I try to execute it in my Java program (that includes JDBC drivers for SQL Server) it says that it doesn't return any result . My Java code is the following : this.statement = this.connect.createStatement(); // Create the statement this.resultats = this.statement.executeQuery(

Execute “sp_msforeachdb” in a Java application

青春壹個敷衍的年華 提交于 2019-11-26 21:57:29
问题 Hi StackOverflow community :) I come to you to share one of my problems... I have to extract a list of every table in each database of a SQL Server instance , I found this query : EXEC sp_msforeachdb 'Use ?; SELECT DB_NAME() AS DB, * FROM sys.tables' It works perfectly on Microsoft SQL Server Management Studio but when I try to execute it in my Java program (that includes JDBC drivers for SQL Server) it says that it doesn't return any result . My Java code is the following : this.statement =