36

I want a to create a new user on a db with only the select permissions (read only access) how can i do this ? i'm working with sql 2008

  • 1
    Hiya - this is the kind of question that ServerFault.com was designed for, since it's more of an administration question as opposed to a programming question. You might have better luck there (and this question might get migrated there from here). Welcome to StackOverflow, though. :) – Amber Sep 01 '09 at 10:34

4 Answers4

54

You could add the user to the Database Level Role db_datareader.

Members of the db_datareader fixed database role can run a SELECT statement against any table or view in the database.

See Books Online for reference:

http://msdn.microsoft.com/en-us/library/ms189121%28SQL.90%29.aspx

You can add a database user to a database role using the following query:

EXEC sp_addrolemember N'db_datareader', N'userName'
John Sansom
  • 41,005
  • 9
  • 72
  • 84
27

You can use Create USer to create a user

CREATE LOGIN sam
    WITH PASSWORD = '340$Uuxwp7Mcxo7Khy';
USE AdventureWorks;
CREATE USER sam FOR LOGIN sam;
GO 

and to Grant (Read-only access) you can use the following

GRANT SELECT TO sam

Hope that helps.

John Sansom
  • 41,005
  • 9
  • 72
  • 84
20

For the GUI minded people, you can:

  • Right click the Database in Management Studio.
  • Choose Properties
  • Select Permissions
  • If your user does not show up in the list, choose Search and type their name
  • Select the user in the Users or Roles list
  • In the lower window frame, Check the Select permission under the Grant column
Scott Lundberg
  • 435
  • 2
  • 10
-2
create LOGIN guest WITH PASSWORD='guest@123', CHECK_POLICY = OFF;

Be sure when you want to exceute the following

DENY VIEW ANY DATABASE TO guest;

ALTER AUTHORIZATION ON DATABASE::BiddingSystemDB TO guest

Selected Database should be Master

gunr2171
  • 16,104
  • 25
  • 61
  • 88