My Technical Notes

Thursday, 14 February 2013

Dropping a ... if it exists

The following code drops a stored procedure if it exists:


IF OBJECT_ID('schema.SpName') IS NOT NULL
BEGIN
    DROP PROCEDURE schema.SpName
END

The following code drops a function if it exists:


IF OBJECT_ID('schema.fnName') IS NOT NULL
BEGIN
    DROP FUNCTION schema.fnName
END

No comments: