View Object Definition In SQL Server 2008
In this article I will demonstrate how to view an object definition in SQL Server using OBJECT_DEFINITION function.
In this article I will demonstrate how to view an object definition in SQL Server using OBJECT_DEFINITION function. Using this function we can view SQL defintion of stored procedures, functions, triggers, views and constraints.
OBJECT_DEFINITION ( object_id )
Here, object_id is an object identifier which uniquely identifies a database object in a given database.
Create a stored procedure.
CREATE PROCEDURE sp_databaseObject
SELECT * FROM sys.databases
Suppose we have this stored procedure and after long period we need to view the its definition. To view SQL definition for mcn database user defined stored procedure, OBJECT_ID function is used within the OBJECT_DEFINITION function to get that user-defined stored procedure. Write following code snippet.
This returns following result: