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

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


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)'