[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

T SQL for usermapping assignment to a user SQL Server 2005

I want to give db_owner to a user , username1 for database dbname1

1. security => logins
2. Right click username1
3. click properties
4. click usermapping
5. choose database dbname1
6. check the db_ower  at the lower pane

When I close the screen and go back in, the "db_owner" is unchecked

I like to know if I can use a T SQL statement to assign this permission , "db_owner" for user "username1" to database "dbname1"

Thanks
0
Greens8301
Asked:
Greens8301
1 Solution
 
chapmandewCommented:
make sure the users exists in the db
create user username for login username


then grant it to the role
EXEC sp_addrolemember 'db_owner', 'username'
0
 
Greens8301Author Commented:
Thanks very much. It worked.
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now