Sql Server 2005 how to change dbo login name

Sql ServerSql Server-2005SecurityActive Directory

Sql Server Problem Overview


I have a database with user 'dbo' that has a login name "domain\xzy". How do I change it from "domain\xzy" to "domain\abc".

Sql Server Solutions


Solution 1 - Sql Server

I figured it out. Within SQL Management Studio you have to right-click on the database -> Properties -> Files -> Owner field. Change this field to the login name/account that you want associated with the "dbo" username for that database. Please keep in mind that the login name/account you choose must already be setup in the sql server under Security -> Logins

Solution 2 - Sql Server

If you are trying to remap a login to a db user you can use sp_change_user_login

exec sp_change_user_login 'Update_One', 'user', 'login'

Solution 3 - Sql Server

PhantomTypist gives a good answer using the GUI. For achieving the same result with TSQL, you can use this code:

USE [My_Database_Name]
GO
EXEC dbo.sp_changedbowner @loginame = N'domain\abc', @map = false
GO

Solution 4 - Sql Server

This is a Windows login, not a SQL Server login, so you cannot 'change' the login name since it is linked to the user account in Active Directory.

Create a new Server Login (Windows) mapped to the new windows user (and remove the old one if necessary). Then in login's Security > User Mapping, permission that login to the appropriate database as user 'dbo' (or assign to the db_owner role)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Question410View Question on Stackoverflow
Solution 1 - Sql Server410View Answer on Stackoverflow
Solution 2 - Sql ServerThadView Answer on Stackoverflow
Solution 3 - Sql ServerMikeView Answer on Stackoverflow
Solution 4 - Sql Serveruser21576View Answer on Stackoverflow