Thursday, July 20, 2023

SQL Server - Write a query to get list of all the schema(s) created by user(s) in database.

Below is the T-SQL query which will give list of all the database schema(s) created by user. It will exclude default Schema(s) created  SQL Server database.:

SELECT Name
FROM sys.schemas
WHERE name NOT IN (
		N'db_accessadmin'
		,N'db_backupoperator'
		,N'db_ddladmin'
		,N'db_datareader'
		,N'db_datawriter'
		,N'db_owner'
		,N'db_denydatareader'
		,N'db_denydatawriter'
		,N'dbo'
		,N'db_securityadmin'
		,N'guest'
		,N'INFORMATION_SCHEMA'
		,N'sys'
		);

No comments:

Post a Comment