Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jameswithers
Starting Member
4 Posts |
Posted - 2008-04-18 : 08:47:35
|
Hi,I am new to transact-sql and this is probably a stupid question. We have a very large number of sql installations and databases and I have a task to change the db owner on every database we have. I am attempting to write a script that will change the owner for all databases in an installation. I am trying to use sp_changedbowner however it does not take a database argument and expects to already be in the database context. I am trying unsuccessfully to use "USE Database" within a cursor loop but this does not work as expected. Does anyone have any ideas as to how I can change the database context, the code I have written is below? Thanksdeclare chdbownCur cursor staticfor select name from master.dbo.sysdatabasesfetch next from chdbownCur into @dbNamewhile @@fetch_status = 0begin use @dbName go exec sp_changedbowner 'hss\sa_fleetwise'" fetch next from chdbownCur into @dbName endclose chdbownCurdeallocate chdbownCur |
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
|
jameswithers
Starting Member
4 Posts |
Posted - 2008-04-18 : 09:05:33
|
Thanks for the advice Ryan, I will give this a shot. |
 |
|
|
|
|