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

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Script Logins

By Gordon Klundt,

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: 2671 | Views in the last 30 days: 8
Related Articles

script to create indexes existing in a database

script to create indexes existing in a database


Create Login Script

Error with Create Login Script


Script Login Differences

Compare the logins and users on two instances and generate a TSQL script to make them the same.


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

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


moving databases,logins

moving database,logins


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

Already a member? Jump in:

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