SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Scripting out grants for 'sa', 'securityadmin' type rights


Scripting out grants for 'sa', 'securityadmin' type rights

Author
Message
Summer90
Summer90
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 7047 Visits: 3831
I am in the process of moving a database from SQL 2005 to 2008 and it has over 1,000 userids. I know how to script out the logins with sp_help_revlogin. My question is how do I script out above the database rights like who has 'sa' rights, 'security admin' type rights. I am sure there is a script to get this out of SQL Server but I cannot seem to find it.
JeremyE
JeremyE
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5813 Visits: 4088
This should do it

CREATE TABLE #srvroles(ServerRole VARCHAR(20), Membername VARCHAR(200), MEMBERSID VARBINARY(MAX))
GO

INSERT #srvroles EXEC sp_helpsrvrolemember

SELECT 'EXEC master..sp_addsrvrolemember @loginame = N'+''''+MemberName+''''+','+'@rolename = N'+''''+ServerRole+''''
FROM #srvroles
GO
DROP TABLE #srvroles


Orlando Colamatteo
Orlando Colamatteo
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38790 Visits: 14411
JeremyE (8/20/2012)
This should do it

CREATE TABLE #srvroles(ServerRole VARCHAR(20), Membername VARCHAR(200), MEMBERSID VARBINARY(MAX))
GO

INSERT #srvroles EXEC sp_helpsrvrolemember

SELECT 'EXEC master..sp_addsrvrolemember @loginame = N'+''''+MemberName+''''+','+'@rolename = N'+''''+ServerRole+''''
FROM #srvroles
GO
DROP TABLE #srvroles


That will give you Fixed Server Role memberships. You'll also need to consult the sys.server_permissions System View to gain the complete picture.

Edit: as a side note sp_addsrvrolemember was marked obsolete in SQL Server 2012 so if this code is going in your toolbox you may want to consider using ALTER SERVER ROLE instead on 2012 instances.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Summer90
Summer90
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 7047 Visits: 3831
Thanks a million gang.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search