Collections:
sys.sql_modules - Getting User Defined Function Definitions Back in SQL Server
How To Get the Definition of a User Defined Function Back in SQL Server Transact-SQL?
✍: FYIcenter.com
If you want get the definition of an existing user defined function back from the SQL Server, you can use the system view called sys.sql_modules, which stores definitions of functions, stored procedures, and views.
The sys.sql_modules holds user defined function definitions identifiable by the object id of each function. The tutorial exercise below shows you how to retrieve the definition of stored procedure, "Sundays" by joining sys.sql_modules and sys.objects:
USE FyiCenterData;
GO
SELECT m.definition
FROM sys.sql_modules m, sys.objects o
WHERE m.object_id = o.object_id
AND o.name = 'Sundays';
GO
definition
-----------------------------------------------
CREATE FUNCTION Sundays()
RETURNS INT
AS BEGIN
DECLARE @date DATETIME;
DECLARE @count INT;
SET @date = '2006-12-31';
SET @count = 0;
WHILE DATEPART(YEAR, @date) <= 2008 BEGIN
SET @date = DATEADD(DAY, 1,
(1 row(s) affected)
⇒ "ALTER FUNCTION" - Modifying Existing Functions in SQL Server
⇐ Generating CREATE FUNCTION Scripts on Existing Functions in SQL Server
2016-12-18, 4091🔥, 0💬
Popular Posts:
Where to find Oracle database server tutorials? Here is a collection of tutorials, tips and FAQs for...
What is sqlservr.exe - Process - SQL Server (SQLEX?PRESS) in SQL Server? Process sqlservr.exe is the...
How To Use GO Command in "sqlcmd" in SQL Server? "sqlcmd" is a command line client application to ru...
What is dba.FYIcenter.com Website about? dba.FYIcenter.com is a Website for DBAs (database administr...
How To Break Query Output into Pages in MySQL? If you have a query that returns hundreds of rows, an...