Programmatically set a DB user to be db_owner
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开发者_如何学JAVA 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]
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.
精彩评论