CREATE OR ALTER in SQL Server

One of my colleague was asking a follow up question on my earlier post DROP IF EXISTS – A handy feature in SQL Server 2016

Do we have something similar for Creating objects?
The good news is that we have “CREATE or ALTER” in SQL Server 2016 to address our long waiting requirement. However, this will not be available in RTM, but only from SP1 and above.

Applies to : SQL Server 2016 SP1 or later versions

Here is a small script to verify the same.
SQL Script:


--Creating the procedure first time
CREATE OR ALTER PROCEDURE SP_TEST
AS
BEGIN
	SELECT 2
END
GO
EXEC SP_TEST
GO
--Altering the procedure 
CREATE OR ALTER PROCEDURE SP_TEST
AS
BEGIN
	SELECT 200
END
GO
EXEC SP_TEST

create-or-replace

Note: This can also be used for Function objects to create or alter operations.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s