How To Get the Definition of a View Out of the SQL Server?
Submitted by: AdministratorIf 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 definitions 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, "ggl_link_view" by joining sys.sql_modules and sys.views:
USE GlobalGuideLineDatabase;
GO
<pre>SELECT m.definition
FROM sys.sql_modules m, sys.views v
WHERE m.object_id = v.object_id
AND v.name = 'ggl_links_top';
GO
definition
-------------------------------------------
CREATE VIEW ggl_links_top (LinkText) AS
SELECT CONVERT(VARCHAR(20),id)
+ ' - ' + CONVERT(VARCHAR(20),counts)
+ ' - ' + url
FROM ggl_links WHERE counts > 1000
(1 row(s) affected)</pre>
Submitted by: Administrator
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, "ggl_link_view" by joining sys.sql_modules and sys.views:
USE GlobalGuideLineDatabase;
GO
<pre>SELECT m.definition
FROM sys.sql_modules m, sys.views v
WHERE m.object_id = v.object_id
AND v.name = 'ggl_links_top';
GO
definition
-------------------------------------------
CREATE VIEW ggl_links_top (LinkText) AS
SELECT CONVERT(VARCHAR(20),id)
+ ' - ' + CONVERT(VARCHAR(20),counts)
+ ' - ' + url
FROM ggl_links WHERE counts > 1000
(1 row(s) affected)</pre>
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | How To Select Some Specific Rows from a Table in MS SQL Server? |
☺ | What Happens If You Insert a Duplicate Key for the Primary Key Column in MS SQL Server? |
☺ | What Are Binary String Data Types in MS SQL Server? |
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
☺ | Can You Roll Back the DDL Statement in a Trigger? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |