SQL Clone
SQLServerCentral is supported by Redgate
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: 2695 | Views in the last 30 days: 5
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