How can I assign the db_owner
role to a user that I have created?
I am able to create a login and add them to the database. I don't know how to change their permission to db_owner
using a SQL query.
I have a feeling I am maybe missing something with my query where I add the user to the database?
Here is the query to add the user to the database
CREATE USER [Driver-SOC-ChrisTest] FOR LOGIN [Driver-SOC-ChrisTest]
WITH DEFAULT_SCHEMA=[dbo]
Login to SQL Server Management Studio. In Object Explorer on the left pane, expand the Databases folder and select the concerned database and navigate to the by expanding Security and Users folders. Right-click the User to which you want to GRANT or REVOKE the permissions.
Creating a user requires alter any user permission, or membership of the db_accessadmin or db_owner database roles. A database owner is a member of the db_owner role by definition. Creating a login requires the alter any login privilege.
dbo is a user and db_owner is a database role. Databases are owned by logins. Whatever login owns the database is aliased as dbo inside the database.
Click the Database Access tab. In the list at the top, in the Permit column, select the check box for the database to which you want to assign the owner role for the CES administrative account. In the Permit in Database Role list, select db_owner. Click OK.
To give the user DBO permissions:
EXEC sp_addrolemember N'db_owner', N'[Driver-SOC-ChrisTest]'
To make the user owner of the database (not advised):
EXEC sp_changedbowner N'[Driver-SOC-ChrisTest]'
I quite often go into the GUI, make the changes I need and then rather than saving by pressing OK, I press the Script button at the top of the dialog and send it to a new window.
This would give you the code the previous poster provided.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With