How to check if a function exists on a SQL database
I need to find out if a function exists on a database, so that I can drop it and create it again. It should basically be something like the following code that I use for stored procedures:
IF EXISTS (select * from dbo.sysobjects where id = object_id(N'[dbo].[SP_TEST]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
Apologies if this is a trivial question, but I’m having a hard time finding the answer.


cheeseballlumpy82 on Mar 05, 2013
This is what SSMS uses when you script using the
DROP and CREATEoptionThis approach to deploying changes means that you need to recreate all permissions on the object so you might consider
ALTER-ing if Exists instead.johan-offer on Mar 05, 2013
I tend to use the Information_Schema:
for functions and then change Routine_type for stored procs: