May 4, 2011 at 9:33 pm
For some purposes, I would like to generate a script for all login accounts used for one specific database.
Does anyone have it?
Many thanks in advance.
May 4, 2011 at 9:52 pm
See if this article helps.
http://sqlblog.com/blogs/eric_johnson/archive/2008/09/30/scripting-sql-server-logins.aspx
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
May 6, 2011 at 12:12 pm
Thank you so much for your input. The script you mentioned is for all logins. I would like to have logins only for one specific user database.
Could you help?
Thanks.
May 6, 2011 at 12:22 pm
i think if you connect to a specific database and run this it might do what you are after:
select 'EXEC sp_help_revlogin ' + name
from sys.database_principals
where type_desc IN ('SQL_USER','WINDOWS_USER')
and principal_id > 4
Lowell
May 9, 2011 at 10:59 am
Lowell (5/6/2011)
i think if you connect to a specific database and run this it might do what you are after:
select 'EXEC sp_help_revlogin ' + name
from sys.database_principals
where type_desc IN ('SQL_USER','WINDOWS_USER')
and principal_id > 4
And if you know the database in question, you could use a 3-part naming convention here, dbname.sys.database_principals. This is often handy if you're trying to generate the script through PowerShell or the like. It allows you to connect to master and then build all the scripts for all DBs.
K. Brian Kelley
@kbriankelley
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply