DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to get database object definition code?

Execute the following Microsoft SQL Server T-SQL scripts for obtaining the definition of Stored Procedures, Triggers, Functions and Views. INFORMATION_SCHEMA views also have certain definitions with some limitations.

------------
-- SQL Server get Stored Procedure, Trigger, VIEW & Function definitions
------------
USE AdventureWorks2008;
GO
-- SQL Server Stored Procedure definition - get Stored Procedure code - sp_helptext
SELECT SchemaName=schema_name(schema_id),
       ObjectName=object_Name(m.object_ID),
       ObjectDefinition=definition
FROM   sys.SQL_Modules m
  INNER JOIN sys.objects o
    ON m.object_id=o.object_id
WHERE  object_Name(m.object_ID) = 'uspGetBillOfMaterials'
GO
/*
SchemaName  ObjectName          ObjectDefinition
dbo   uspGetBillOfMaterials     CREATE PROCEDURE ....
*/
 
-- T-SQL get VIEW definition
SELECT SchemaName=schema_name(schema_id),
       ObjectName=object_Name(m.object_ID),
       ObjectDefinition=definition
FROM   sys.SQL_Modules m
  INNER JOIN sys.objects o
    ON m.object_id=o.object_id
WHERE  object_Name(m.object_ID) = 'vSalesPersonSalesByFiscalYears'
GO
/*
SchemaName  ObjectName                      ObjectDefinition
Sales vSalesPersonSalesByFiscalYears        CREATE VIEW .....
*/

-- System view definition

SELECT OBJECT_DEFINITION(object_id('INFORMATION_SCHEMA.TABLES'))

------------

-- Old way of getting definition code
EXEC sp_helptext 'Sales.vSalesPersonSalesByFiscalYears'
GO
 
 
-- Get all object definitions: SPROC, TRIGGER, VIEW & FUNCTION
SELECT SchemaName=schema_name(schema_id),
       ObjectName=object_Name(m.object_ID),
       ObjectDefinition=definition
FROM   sys.SQL_Modules m
  INNER JOIN sys.objects o
    ON m.object_id=o.object_id

ORDER BY SchemaName, ObjectName

------------

Related links:

How to: View the Definition of a Stored Procedure (SQL Server Management Studio)

How to keyword search programming objects?

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE