List user schemas in all databases in SQL Server instance

Query below list user created schemas in all databases.


declare @query nvarchar(max)

set @query = 
(select 'select ''' + name + ''' as database_name,
              s.Name COLLATE DATABASE_DEFAULT as schema_name,
     COLLATE DATABASE_DEFAULT as schema_owner 
        FROM ['+ name + '].sys.schemas s
        JOIN ['+ name + '].sys.sysusers u on u.uid = s.principal_id
        where u.issqluser = 1
              and not in (''sys'', ''guest'', ''INFORMATION_SCHEMA'')
        union all '
    from sys.databases 
    where database_id > 4
    for xml path(''), type).value('.', 'nvarchar(max)')

set @query = left(@query,len(@query)-10) 
                        + ' order by database_name, schema_name'

execute (@query)


  • database_name - name of the database within schema resides
  • schema_name - name of the schema
  • schema_owner - name of the schema owner


  • One row represents one user schema
  • Scope of rows: all user schemas from all databases
  • Ordered by database name and schema name

Sample results

There are no comments. Click here to write the first comment.