September 15, 2004 at 6:52 pm
Hello
I'm looking for a way to write a script that will run against a SQL Server's databases, and look for a certain table in each database. Is there any way to accomplish this?
September 15, 2004 at 8:40 pm
It's not pretty, but see whether this helps:
declare @sql varchar(400)
set @sql = 'select * from ?.information_schema.tables where table_name = ''[tablename]'''
exec sp_msforeachdb @sql
--replace [tablename] with the name of the table you are searching for
The output can be tidied up fairly simply through the use of a temp table.
Regards
Phil
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
September 16, 2004 at 5:16 am
Phil, that worked GREAT! Thank you very much. 1/2 my goal is worked out.
I now need to take each db indentified as possesing the "looked for table", and do a dump (xml, flat, whatever) of everything in it, minus data. This would include sp's, triggers, tables, jobs, etc..
Any ideas?! BTW, thanks again!
September 16, 2004 at 6:14 pm
Glad I could help.
I imagine you're after a SQL script that will recreate the database (minus the data). The way that I would do this is in Enterprise Manager. Right click a database, All Tasks, Generate SQL Script. Click on Show All and select Script All Objects.
This will not script the jobs, which are part of a system database (msdb I think) - but you can script jobs separately just by right-clicking them in EM ... as above.
Regards
Phil
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
September 17, 2004 at 3:30 am
Here's EXACTLY what I'm after..my company puts out a product which adds a database, or databases, to someone's SQL server. We want a script we can give them via email/ftp that will
A. Hunt through their server and look for a specific table in all their databases. (done)
B. For each database the above (A) returns, the script dumps all info about EACH database into a text file. We'd like to be able to recreate their environment if needed.
THat's what I'm looking to do. Part A is done, thanks to you!
September 21, 2004 at 8:10 am
Hi!
You have to write a program using DMO.
If you do not want to write - look here: http://www.sqlservercentral.com/scripts/contributions/1151.asp
It's your part B and even more.
Good Luck!
September 21, 2004 at 11:48 pm
>We'd like to be able to recreate their environment if needed.
See "Backups"?
--Jeff Moden
Change is inevitable... Change for the better is not.
September 22, 2004 at 12:00 am
Also be aware that the information_schema.* views only return results within the context of the executing user.
ie - if you're logged on as (any) user, and there is a table which this user has no permissions on, information_schema.* views will not return any information about that object. (though it does still exists)
/Kenneth
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply