November 13, 2013 at 8:33 am
Hi,
I would like to execute a 100 lines script in all the user databases of a sql server instance.
Can someone suggest how to do it ?
Thanks in advance.
Smith.
November 13, 2013 at 8:35 am
Powershell is an option.
or
exec sp_msforeachdb 'USE ?; SELECT ?;'
Personally, I'd consider writing a generic powershell script which took a .sql file as parameter.
November 13, 2013 at 9:37 am
I do not want to use sp_msforechdb because its a long script.
Also it may be necessary to execute that in a few speceific databaseas in future.
I tried using cursor by saving the required databases in a temptable browsing through each tables.
Pbm is it's actualy not changing the database. 'use '+@dbname doesn't work.
Thanks.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply