Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 database refresh

Author  Topic 

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2010-06-09 : 00:12:25
Hi
i've a database in prod and the same in QA. i need to refresh the database from prod to QA, but all the QA users needs to have the same permissions as it is. it means i need to maintain the same users as it is...pls suggest..
sp_helprevlogin works for this?

thanks in advance

Arnav
Even you learn 1%, Learn it with 100% confidence.

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-06-09 : 02:24:08
Are the permissions in QA different from PROD? sp_helprevlogin will generate a script to recreate all logins to the server with their existing passwords (hashed) but it will not script the permissions in the database. If the permissions are different in QA than in PROD you probably need to script the permissions in QA first using something like this: http://vyaskn.tripod.com/scripting_permissions_in_sql_server_2005.htm

If the permissions in PROD are the correct ones you can basically do the backup/restore and then run an "unorphan"-script like this:
DECLARE 
@SQL VARCHAR(1000),
@SuccessCount INT,
@ErrorCount INT

SET @SuccessCount = 0
SET @ErrorCount = 0

DECLARE curSQL CURSOR FOR
SELECT 'EXEC sp_change_users_login ''UPDATE_ONE'', ''' + name + ''', ''' + name + ''''
FROM sysusers
WHERE issqluser = 1 AND name NOT IN ('guest', 'dbo', 'sys', 'INFORMATION_SCHEMA')

OPEN curSQL

FETCH curSQL INTO @SQL

WHILE @@FETCH_STATUS = 0
BEGIN
BEGIN TRY
EXEC (@SQL)
SET @SuccessCount = @SuccessCount + 1
END TRY
BEGIN CATCH
SET @ErrorCount = @ErrorCount + 1
END CATCH

FETCH curSQL INTO @SQL
END

CLOSE curSQL
DEALLOCATE curSQL

RAISERROR (N'%d of the Logins were unorphaned successfully, %d logins don''t exist in the current master database', 1, 1, @SuccessCount, @ErrorCount)


- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page
   

- Advertisement -