Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

SQL SERVER CREATE OR ALTER Supported in Service Pack 1 of SQL Server 2016

$
0
0

SQL SERVER   CREATE OR ALTER Supported in Service Pack 1 of SQL Server 2016
There are many enhancements which were introduced in Service Pack 1 of SQL Server 2016. If you are a developer, then you can easily understand this productivity improvement. Does below code looks familiar to you? Let us learn aboutCREATE OR ALTER Supported in Service Pack 1 of SQL Server 2016. IF EXISTS (SELECT NAME FROM SYSOBJECTS WHERE NAME = 'sp_SQLAuthority' AND TYPE = 'P') BEGIN DROP PROCEDURE sp_SQLAuthority END GO CREATE PROCEDURE sp_SQLAuthority (@Params ...) AS BEGIN ... END GO

So, if you are deploying any script to SQL Server and you are not aware of the situation in production, whether a stored proc was already previously deployed or not. Developer need to put a check and drop if it’s already there and then create it.

Oracle has been having CREATE or REPLACE from a long time and there have been feedbacks given to the Microsoft SQL product team to do something about it.

CREATE OR ALTER statement

Create or Replace xxx

Finally, they have heard it and introduced this change in Service Pack 1 of SQL Server 2016. Here are the few objects which would allow such syntax

Stored procedures Triggers User-defined functions Views

Unfortunately, it would not work for Objects that require storage changes like table, index. It is not allowed for CLR procedure also.

Here is the usage

CREATE OR ALTER PROCEDURE usp_SQLAuthority AS BEGIN SELECT 'ONE' END GO

Do you think this is a good enhancement? I would highly encourage to read below blog on a similar feature. SQL Server 2016 T-SQL Enhancement “Drop if Exists” clause

Were you aware of this? Do you want me to blog about SP1 enhancement?

Reference: Pinal Dave ( http://blog.sqlauthority.com )


Viewing all articles
Browse latest Browse all 3160

Trending Articles