Tuesday, September 10, 2013

How To Get the Definition of a View Out of the SQL Server?

If you want get the definition of an existing view back from the SQL Server, you can use the system view called sys.sql_modules, which stores defitions of views and procedures.
The sys.sql_modules holds view definitions identifiable by the object id of each view. The tutorial exercise below shows you how to retrieve the definition of view, "fyi_link_view" by joining sys.sql_modules and sys.views:

USE FyiCenterData;

SELECT m.definition 
   FROM sys.sql_modules m, sys.views v
   WHERE m.object_id = v.object_id
   AND v.name = 'fyi_links_top';   
CREATE VIEW fyi_links_top (LinkText) AS
      + ' - ' + CONVERT(VARCHAR(20),counts) 
      + ' - ' + url 
   FROM fyi_links WHERE counts > 1000
(1 row(s) affected)

No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)


Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive