List schemas in SQL Server database

Query below lists all schemas in SQL Server database. Schemas include default db_* , sys, information_schema and guest schemas.

If you want to list user only schemas use this script.

Query

select s.name as schema_name, 
    s.schema_id,
    u.name as schema_owner
from sys.schemas s
    inner join sys.sysusers u
        on u.uid = s.principal_id
order by s.name

Columns

  • schema_name - schema name
  • schema_id - schema id, unique within the database
  • schema_owner - principal that owns this schema

Rows

  • One row represents one schema in a database
  • Scope of rows: all schemas in a database, including default ones
  • Ordered by schema name

Sample results

Here is a view of database schemas in SSMS:

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
0
There are no comments. Click here to write the first comment.