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
Greens8301Asked:
Who is Participating?
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.