How can I provide someone ,only read permission to all databases in my server at a time.

  • Please help ???

  • You need to create a login, map the user to the login and then give datareader permissions to the users, basically select permission.

    You can script this too!

  • server have 70 Databases. I want to give only read permission to all at a time not to one by one Database.

  • Try this article, http://msdn.microsoft.com/en-us/library/aa259605(v=sql.80).aspx

    For 70 databases at a time, not sure wait for the experts.

  • SET NOCOUNT ON

    -- Get the name of all databases

    DECLARE AllDatabases CURSOR FOR

    SELECT name FROM master..sysdatabases

    where name not in ('master','tempdb')

    -- Open Cursor

    OPEN AllDatabases

    -- Define variables needed

    DECLARE @DB NVARCHAR(128)

    DECLARE @COMMAND NVARCHAR(128)

    -- Get First database

    FETCH NEXT FROM AllDatabases INTO @DB

    -- Process until no more databases

    WHILE (@@FETCH_STATUS = 0)

    BEGIN

    -- Build command to put database into DDBO ONLY mode

    set @command ='USE ' + @db +

    ' CREATE USER reader FOR LOGIN [reader]'

    -- Print command to be processed

    print @command

    -- Process Command

    exec (@command)

    set @command = 'USE ' + @db +

    ' EXEC sp_addrolemember ''db_datareader'' ,''reader'''

    -- Print command to be processed

    print @command

    -- Process command

    exec (@command)

    -- Get next database

    FETCH NEXT FROM AllDatabases INTO @DB

    END

    -- Close and Deallocate Cursor

    CLOSE AllDatabases

    DEALLOCATE AllDatabases

    Reused the code of: http://www.sqlservercentral.com/Forums/Topic410613-90-1.aspx

    used as login: reader, but change it to youre liking but make sure its available

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply