List views in Azure SQL database with their scripts

Query below lists views in a database with their definition.

Query

select schema_name(v.schema_id) as schema_name,
       v.name as view_name,
       v.create_date as created,
       v.modify_date as last_modified,
       m.definition
from sys.views v
join sys.sql_modules m 
     on m.object_id = v.object_id
 order by schema_name,
          view_name;

Columns

  • schema_name - view schema name
  • view_name - view name
  • created - date and time was created
  • last_modified - view last modification date and time
  • definition - view definition script including 'create view' statement

Rows

  • One row represents one view
  • Scope of rows: all views in database
  • Ordered by schema name, view name

Sample results