February 5, 2007 at 8:48 am
What's the best way to iterate through all the names of an existing db, so I can take the dbname and put it in a variable to do further action on it.
I know there are different methods, and will accept a cursor, but thought 2005 will have newer more efficient way. Please provide samplet code. TIA!
February 5, 2007 at 8:59 am
sp_msforeachdb will allow you to execute the same block of code using each database.
What you want to do is substitute in a question mark for the name of the database....
sp_msforeachdb 'select ''?'' as db_nm, * from ?..sysobjects where xtype = ''P'' '
That would, for instance, list all stored procs in all databases and the name of the db next to them. 😉
February 5, 2007 at 9:28 am
Thx for the quick reply.
While I appreciate this method, I'd prefer not to use sp_msforeachdb, b/c I need to use the dbname in a sp script.
February 5, 2007 at 9:57 am
Can we see the script to see if we can change it there?
February 5, 2007 at 10:18 am
Thx, all - I used a forward-only cursor afterall - doesn't take much resources.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply