List views in Azure SQL database with their scripts

Query below lists views in a database with their definition.

Confused about your PostgreSQL database?

You don't have to be. There's an easy way to understand the data in your databases.

I want to understand

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

Create beautiful and useful documentation of your PostgreSQL

Generate convenient documentation of your databases in minutes and share it with your team. Capture and preserve tribal knowledge in shared repository.

See how it works

Confused about your PostgreSQL database?

You don't have to be. There's an easy way to understand the data in your databases.

I want to understand