April 20, 2011 at 10:08 pm
Please help ???
April 20, 2011 at 10:14 pm
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!
April 21, 2011 at 12:23 am
server have 70 Databases. I want to give only read permission to all at a time not to one by one Database.
April 21, 2011 at 2:52 am
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.
April 21, 2011 at 3:39 am
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