Monday, March 26, 2012

How to change owner of database? Please help!

Hi,

I just transferred my website and database (SQL 2000) to a new host who's SQL Manager doesn't support the previous username I had for the database.

The previous owner of database tables etc was Database_master and now I want to change it to just Master.

Please advise! Someone else designed the website for me, and honestly I have just some basic knowledge of databases and such.

I would appreciate help and if possible with detailed steps.

Many thanks in advance,

Isje

From BOL at http://msdn2.microsoft.com/en-us/library/ms178630.aspx, use:

sp_changedbowner (Transact-SQL)

Changes the owner of the current database.

sp_changedbowner [ @.loginame = ] 'login'
[ , [ @.map= ] remap_alias_flag ]

|||

Thanks very much for your reply. I found a solution in the meantime. It took me some time though :(

Here is what I did:

1. Run this script in Query Analyser (here the owner becomes newowner) :


SELECT 'EXEC(''sp_changeobjectowner @.objname = '''''+
ltrim(u.name) + '.' + ltrim(s.name) + ''''''
+ ', @.newowner = newowner'')'
FROM sysobjects s,
sysusers u
WHERE s.uid = u.uid
AND u.name <> 'dbo'
AND xtype in ('V', 'P', 'U')
AND u.name not like 'INFORMATION%'
order by s.name

2. Then Copy-paste the result in Query analayser, and run!

Big Smile

No comments:

Post a Comment