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.
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