TSQL to Map User to Database

前端 未结 6 1646
刺人心
刺人心 2020-12-08 09:43

So I\'m not able to user enterprise manager to do this... If I was I wouldn\'t even be asking this question. So I\'m wondering if there is a way through TSQL to execute a co

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 09:53

    Officially, you want to create a database user that is mapped to a login. To do that, you would use:

    Create User  For LOGIN 
    

    This obviously requires that the login exist. After that you would then call:

    exec sp_addrolemember 'db_owner', 
    

    This presumes that the account with which you are connecting to the database has privileges to add members to the db_owner role.

提交回复
热议问题