January 10, 2010 at 8:17 am
Hi
when i have restored database from production to UAT .as production users will be different for all store procedures., so i need to add all UAT users to 50 store proc.
is there any Script to restore all Existing Users of UAT to the newly restored database .
or
any script to add one user to all 50 store procedures at a time.
January 10, 2010 at 11:27 am
This script will allow you to add a user to all the stored procedures that you choose at once:
USE YourDatabase
DECLARE @Namevarchar(150),
@sqlvarchar(500)
DECLARE Perm_Cursor CURSOR FOR
SELECT [Name]
FROM sysobjects
WHERE xtype ='P' AND [NAME] NOT LIKE 'dt_%'
OPEN Perm_Cursor
FETCH NEXT FROM Perm_Cursor
INTO @Name
WHILE @@FETCH_STATUS = 0
BEGIN
SET @sql = 'GRANT EXECUTE ON [' + @Name + '] TO YourUserName'
EXEC(@SQL)
FETCH NEXT FROM Perm_Cursor
INTO @Name
DEALLOCATE Perm_Cursor
END
CLOSE Perm_Cursor
You could add in additional parameters to the cursor declaration to filter down which ones you want to add the user to.
January 10, 2010 at 11:44 am
would it be easier to create a role in the production database that has execute access to the 50 procedures, and then use a variation of Seth's script to add each user to the appropriate role?
then when you copy the database to UAT, you just add the users to that role after the restoration and they can test?
Lowell
January 10, 2010 at 1:11 pm
Please don't cross post. It just wastes peoples time and fragments replies. Especially when you post one 6 hours after the other. 6 hours is not long to wait, especially on a weekend.
No replies more to this thread please. Direct replies to: http://www.sqlservercentral.com/Forums/Topic845004-359-1.aspx
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply