SDU Tools: Script SQL Logins for SQL Server

In our free SDU Tools for developers and DBAs, we've added a lot of scripting tools. To script out SQL authenticated logins (as opposed to Windows logins), we have ScriptSQLLogins.

You can see how to use it in the main image above. It's a function, that takes a list of the logins to script. You can pass the value ALL or a comma-delimited list.

Importantly, as well as the login and the hashed password, it also scripts other details:

It includes the default database, and policy check status, but importantly, it also scripts the SID (security ID) associated with the login, so if you recreate it on another server, you'll have the same ID, and you won't end up with orphaned users. That's a problem that I see all the time, where users restore a database, recreate the logins, but the logins don't still have the ability to connect to the database. It's because the names are the same, but the SIDs are different. This tool avoids that issue.

One key advantage of having these scripting procedures and functions is that you incorporate them into other applications, and programmatically perform the scripting if you need to.

But if you just want to create a script, that works too.

You can see it in use in the main image above, and you can watch it in action here:

To become an SDU Insider and to get our free tools and eBooks, please just visit here:

http://sdutools.sqldownunder.com

Leave a Reply

Your email address will not be published.