Search

Wednesday, July 18, 2012

Get the view definition from a SQL Server using ADO

Use the below query to get the view definition from a SQL server using ADO. This is applicable for SQL Server 2005 and later.


SELECT definition FROM sys.objects AS O JOIN sys.sql_modules AS M ON M.object_id = O.OBJECT_ID where O.type = 'V'


If you want to get the definition of a particular view then use below query:


SELECT definition FROM sys.objects AS O JOIN sys.sql_modules AS M ON M.object_id = O.OBJECT_ID where O.type = 'V' AND o.object_id = object_id( 'dbo.TotalView')


Note:


If the view was last modified with ALTER VIEW, then the script will be an ALTER VIEW statement instead of CREATE VIEW statement.



No comments:

Post a Comment