Tuesday 2 January 2018

Retrieve the view definition from a SQL Server

Is there a way to retrieve the view definition from a SQL Server?

YES!

Use this Query:

select definition
from sys.objects     o
join sys.sql_modules m on m.object_id = o.object_id
where o.object_id = object_id( 'dbo.MyView')
  and o.type      = 'V'