1

I am looking for a way to change the option of "default database" to master for all the logins on my instance from current user database in order to maintain the consistency.

Application code logins are all set to use " USE [DBNAME]" so changing all logins to master should be good.

Is there a way to have the script check first or list all logins with default databases and then listing/printing the changes to change the above?

Thanks

0
1

You can use sys.server_principals to find default database and alter login to change it.

SELECT name,
       default_database_name,
       'alter login ['+name+'] with default_database=master;'
FROM sys.server_principals
WHERE default_database_name <> 'master';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.