September 14, 2008 at 2:01 am
Hi,
I have an SP with me which provides me with all the DB Logins and Roles associated. I need to get Server Roles too along with it.
Can someone provide me with a script which will give me all the DB & Server roles for all logins?
OR
Pls provide me with a script to get all Logins and their associated Server Roles for a DB.
Thnx in Adv
Any help is really appreciated!
Manu
September 14, 2008 at 8:42 am
Logins don't have database roles, only users.
This information is easily stored in security system catalog views.
September 15, 2008 at 7:39 am
the following reverse engineers the code to re-apply all server roles granted to logins:
set quoted_identifier off
set nocount on
select 'exec sp_addsrvrolemember ' +"'" +loginname +"',"
+"'sysadmin'"
from syslogins where sysadmin = 1
UNION ALL
select 'exec sp_addsrvrolemember ' +"'" +loginname +"',"
+"'securityadmin'"
from syslogins where securityadmin = 1
UNION ALL
select 'exec sp_addsrvrolemember ' +"'" +loginname +"',"
+"'serveradmin'"
from syslogins where serveradmin = 1
UNION ALL
select 'exec sp_addsrvrolemember ' +"'" +loginname +"',"
+"'setupadmin'"
from syslogins where setupadmin = 1
UNION ALL
select 'exec sp_addsrvrolemember ' +"'" +loginname +"',"
+"'processadmin'"
from syslogins where processadmin = 1
UNION ALL
select 'exec sp_addsrvrolemember ' +"'" +loginname +"',"
+"'diskadmin'"
from syslogins where diskadmin = 1
UNION ALL
select 'exec sp_addsrvrolemember ' +"'" +loginname +"',"
+"'dbcreator'"
from syslogins where dbcreator = 1
UNION ALL
select 'exec sp_addsrvrolemember ' +"'" +loginname +"',"
+"'bulkadmin'"
from syslogins where bulkadmin = 1
---------------------------------------------------------------------
July 17, 2010 at 12:45 am
Hi,
for db logins try it:sp_helprevlogin
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply