In this article, we will be discussing about how you can change the Database Owner in a SQL Server Database.
About the “dbo” User in SQL Server
In SQL Server, the dbo (Database Owner) is a special user that has all the necessary permissions to perform all activities in the database. This user exists in all SQL Server databases.
Usually, there are SQL Server or Windows logins mapped to the dbo user, thus “inheriting” the permissions of the database’s dbo user and being able to perform all the activities in the database that the dbo user can perform.
How you can Change the Database Owner User in SQL Server 2000
In some cases, due to various changes a DBA might perform in SQL Server, you may discover that the dbo user is orphaned, meaning that there is not any login mapped to this user.
If you would like to change this, thus mapping a login to the dbo user you can make use of the “sp_changedbowner” system stored procedure.
The syntax as provided in the T-SQL reference library is the following:
sp_changedbowner [ @loginame= ] 'login' [ , [ @map= ] remap_alias_flag ]
For example, if you want to make the SQL Server Login ‘Tom‘ the owner of the database “TestDB” you can use the following T-SQL script:
USE TestDB; GO EXEC sp_changedbowner 'Tom'; GO
Additionally, if you want to make a Windows Login, for example ‘SampleDomainTestUser‘ the owner of the database “TestDB” you can use the following T-SQL script:
USE TestDB; GO EXEC sp_changedbowner 'SampleDomainTestUser'; GO
Please also note that only members of the sysadmin fixed server role can execute the stored procedure sp_changedbowner.
How you can Change the Database Owner User in SQL Server 2005 and Later
In SQL Server 2005 or later, you can make use of the “ALTER AUTHORIZATION” command as sp_changedbowner will be removed in a future version of SQL Server.
Example:
ALTER AUTHORIZATION ON database::TestDB TO Tom; GO
Strengthen your SQL Server Administration Skills – Enroll to our Online Course!
Check our online course on Udemy titled “Essential SQL Server Administration Tips” (special limited-time discount included in link).
Via the course, you will learn essential hands-on SQL Server Administration tips on SQL Server maintenance, security, performance, integration, error handling and more. Many live demonstrations and downloadable resources included!
Featured Online Courses:
- SQL Server 2022: What’s New – New and Enhanced Features
- Working with Python on Windows and SQL Server Databases
- Introduction to Azure Database for MySQL
- Boost SQL Server Database Performance with In-Memory OLTP
- Introduction to Azure SQL Database for Beginners
- Essential SQL Server Administration Tips
- SQL Server Fundamentals – SQL Database for Beginners
- Essential SQL Server Development Tips for SQL Developers
- Introduction to Computer Programming for Beginners
- .NET Programming for Beginners – Windows Forms with C#
- SQL Server 2019: What’s New – New and Enhanced Features
- Entity Framework: Getting Started – Complete Beginners Guide
- Data Management for Beginners – Main Principles
- A Guide on How to Start and Monetize a Successful Blog
Read Also:
- SQL Server Installation and Setup Best Practices
- The TempDB System Database in SQL Server
- SQL Server 2016: TempDB Enhancements
- tempdb growth
- Introduction to SQL Server Machine Learning Services
- Essential SQL Server Administration Tips
- …more
Check our other related SQL Server Administration articles.
Subscribe to our newsletter and stay up to date!
Check out our latest software releases!
Check out our eBooks!
Rate this article:
Reference: SQLNetHub.com (https://www.sqlnethub.com)
© SQLNetHub
Artemakis Artemiou, a distinguished Senior Database and Software Architect, brings over 20 years of expertise to the IT industry. A Certified Database, Cloud, and AI professional, he earned the Microsoft Data Platform MVP title for nine consecutive years (2009-2018). As the founder of SQLNetHub and GnoelixiAI Hub, Artemakis is dedicated to sharing his knowledge and democratizing education on various fields such as: Databases, Cloud, AI, and Software Development. His commitment to simplicity and knowledge sharing defines his impactful presence in the tech community.