Skip Navigation

SQL If Exists Then Drop (Updated)


In my original post back in 2013, I described some ways to add "if exists then drop" statements to multiple SQL script types. I'm well overdue for an update on that post as SQL Server 2016 added most of the below syntax. As with my last post, enjoy the quick reference!

Drop Statement 'IF EXISTS'


DROP FUNCTION IF EXISTS [dbo].[enterFunctionNameHere];
GO

DROP PROCEDURE IF EXISTS [dbo].[enterStoredProcedureNameHere];
GO

DROP TABLE IF EXISTS [dbo].[enterTableNameHere];
GO

DROP VIEW IF EXISTS [dbo].[enterViewNameHere];
GO

Create or Alter Procedures

In addition to the above, you can now use CREATE OR ALTER directly within your stored procedure script.

CREATE OR ALTER PROCEDURE [dbo].[enterStoredProcedureNameHere]
(
	-- params here
)
AS
BEGIN 
    -- sproc here
END