September 8, 2016 at 11:42 am
The code for a SP goes in this table. Similarly how can we get the DEFINITION of a view
select [definition] AS ProcDef from sys.sql_modules
September 8, 2016 at 12:04 pm
mw112009 (9/8/2016)
The code for a SP goes in this table. Similarly how can we get the DEFINITION of a view
select [definition] AS ProcDef from sys.sql_modules
USE YourDatabase
GO
SELECT OBJECT_NAME(object_id), definition
FROM sys.sql_modules
WHERE OBJECT_NAME(object_id) like 'YourViewName'
Sue
September 8, 2016 at 1:20 pm
mw112009 (9/8/2016)
The code for a SP goes in this table. Similarly how can we get the DEFINITION of a view
select [definition] AS ProcDef from sys.sql_modules
Exactly the same way. Views, functions and stored procedures all have their definitions available from the sys.sql_modules catalog view
CREATE VIEW MyView
AS
SELECT 1 AS Col1;
GO
SELECT * FROM sys.sql_modules WHERE object_id = OBJECT_ID('MyView')
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 8, 2016 at 2:06 pm
Alternatively, you can bypass sys.sql_modules all together and use OBJECT_DEFINITION.
CREATE VIEW MyView
AS
SELECT 1 AS Col1;
GO
SELECT OBJECT_DEFINITION(OBJECT_ID('MyView'))
-- Itzik Ben-Gan 2001
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply