Skip to content

Instantly share code, notes, and snippets.

@ghotz
Last active April 17, 2019 17:14
Show Gist options
  • Save ghotz/9c081e10ee2bc50cb2f82997a902bc73 to your computer and use it in GitHub Desktop.
Save ghotz/9c081e10ee2bc50cb2f82997a902bc73 to your computer and use it in GitHub Desktop.
Get all users with a non standard default schema for all databases
EXEC sp_MSforeachdb '
USE [?];
SELECT DB_NAME() AS database_name, name AS principal_name, default_schema_name
FROM sys.database_principals
WHERE default_schema_name NOT IN (''dbo'', ''guest'');
';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment