Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Script Logins

By Gordon Klundt, 2011/04/04

I wrote this procedure mainly as an exercise in converting varbinary to a usable string in a CTE, but it ended up being a suitable replacement for a procedure (two procedures, actually) that have annoyed me for a while.

Here are the reasons I like this script better than sp_help_revlogin:

  • One procedure instead of two.
  • Does not have to exist in the master database.
  • Scripts "creating message" output AS WELL AS whether or not the creation succeeded so you can tell where it actually had an error if there is one.
  • Checks for the existence of the login BEFORE it tries to create it.
  • States whether or not the login already existed or was created.
  • Allows you script logins for a single database as opposed to the whole server.
  • Allows you to script logins with [master] as the default database in case you are preparing a server where the databases do not exist for a given login.
  • Uses CTEs for the password and SID hash (welcome to 2005).

Hope this is useful to someone, good luck and enjoy.

Total article views: 2449 | Views in the last 30 days: 18
 
Related Articles
FORUM

script to create indexes existing in a database

script to create indexes existing in a database

FORUM

Create Login Script

Error with Create Login Script

FORUM

Script out Logins and Users for Every Database in a SQL instance

Script out Logins and Users for Every Database in a SQL instance

FORUM

Sql Script to change the Login Permission

Sql Script to change the Login Permission

FORUM

moving databases,logins

moving database,logins

Tags
logins    
script    
sp_help_revlogin    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones