19

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]
Ryan Gates
  • 4,501
  • 6
  • 50
  • 90
Chris James
  • 11,571
  • 11
  • 61
  • 89
  • See this answer for SQL Server 2008 http://stackoverflow.com/questions/3998634/sql-server-2008-how-do-i-grant-privileges-to-a-username – Richard Chambers Nov 21 '13 at 02:02

2 Answers2

33

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]'
Andomar
  • 232,371
  • 49
  • 380
  • 404
24

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.

enter image description here

This would give you the code the previous poster provided.

G S
  • 35,511
  • 22
  • 84
  • 118
SPE109
  • 2,911
  • 1
  • 19
  • 16