How do I grant read access for a user to a database in SQL Server?

后端 未结 1 1929
野性不改
野性不改 2020-12-08 13:51

I want to grant access to a user to a specific database with read and write access. The user is already available in the domain but not in the DB.

So, how can I give

相关标签:
1条回答
  • 2020-12-08 14:07

    This is a two-step process:

    1. you need to create a login to SQL Server for that user, based on its Windows account

      CREATE LOGIN [<domainName>\<loginName>] FROM WINDOWS;
      
    2. you need to grant this login permission to access a database:

      USE (your database)
      CREATE USER (username) FOR LOGIN (your login name)
      

    Once you have that user in your database, you can give it any rights you want, e.g. you could assign it the db_datareader database role to read all tables.

    USE (your database)
    EXEC sp_addrolemember 'db_datareader', '(your user name)'
    
    0 讨论(0)
提交回复
热议问题