Default Database Script

Often the sp_help_revlogin (http://support.microsoft.com/kb/246133/) Stored Procedure is used to transfer logins from one server to another. In the June WARDY IT Newsletter (https://www.wardyit.com/newsletters/jun2006.htm) we showed how to build on this to also script the Server Roles for each login.  One other thing that would be nice is if this script also generated the Default Databases for each login.  The TSQL script below can be used to build on sp_help_revlogin to generate a script to set the Default Database for each login.

SELECT ‘EXEC sp_defaultdb ”’ + name + ”’, ”’ + dbname + ””
FROM master.dbo.syslogins