SQL Server 2005 has great sys.XXX
views on the system catalog which I use frequently.
What stumbles me is this: why is there a sys.procedures
I find UDFs are very handy and I use them all the time.
I'm not sure what Microsoft's rationale is for not including a sys.functions equivalent in SQL Server 2005 (or SQL Server 2008, as far as I can tell), but it's easy enough to roll your own:
CREATE VIEW my_sys_functions_equivalent
AS
SELECT *
FROM sys.objects
WHERE type IN ('FN', 'IF', 'TF') -- scalar, inline table-valued, table-valued
Another way to list functions is to make use of INFORMATION_SCHEMA views.
SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'FUNCTION'
According to the Microsoft web site "Information schema views provide an internal, system table-independent view of the SQL Server metadata. Information schema views enable applications to work correctly although significant changes have been made to the underlying system tables". In other words, the underlying System tables may change as SQL gets upgraded, but the views should still remain the same.
try this :
SELECT * FROM sys.objects
where type_desc = 'SQL_SCALAR_FUNCTION'
To extend upon @LukeH's answer, to return the function definitions as well requires a join to the sys.sql_modules
table. So the query for this is:
SELECT O.name as 'Function name', M.definition as 'Definition', O.object_id
FROM sys.objects as O INNER JOIN sys.sql_modules as M
ON O.object_id = M.object_id
WHERE type IN ('FN', 'IF', 'TF') -- scalar, inline table-valued, table-valued
where the above displays the function name, its definition and the object identifier respectively.
incidentally, wouldn't you want to include type = 'FS'?
name type type_desc
getNewsletterStats FS CLR_SCALAR_FUNCTION
that's what the item in sys.objects corresponds with for my UDF which is derived from an external DLL
This does not add anything new, but I found the following easier to remember:
select * from sys.objects where type_desc like '%fun%'