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.
Syntax
OBJECT_DEFINITION ( object_id )
Here, object_id is an object identifier which uniquely identifies a database object in a given database.
Example
Create a stored procedure.
USE mcn
CREATE PROCEDURE sp_databaseObject
AS
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.
USE mcn
GO
SELECT OBJECT_DEFINITION(OBJECT_ID('sp_databaseObject'))
GO
This returns following result:
