Create or Alter syntax in SQLServer

SQLServer 2016 sp1 introduces a lot of new features..One of them is most requested DIE syntax style statements..

Assume you want to create a stored procedure and you are not sure if it exists.So the normal old syntax goes like this..

if exists(Select 1 from sys.procedures where name='test_proc')
drop proc test_proc


create proc test_proc
as
begin
return 1
end

With 2016 SP1,you can do like below

CREATE OR ALTER PROCEDURE test_proc
as
begin
return 1
end

as you can see,Code can be simplified a lot..Please read this blog post as well from SQLServer team for more details..

CREATE OR ALTER – another great language enhancement in SQL Server 2016 SP1

Advertisements