Saturday, November 19, 2016

Now SQL Server supports CREATE OR ALTER statement

Another great enhancement with SQL Server 2016 SP1 is the support of CREATE OR ALTER statement with Stored Procedures, Views, Triggers and User-Defined functions. Now you do not need to have a statement for checking whether the object is exist before modifying and then start with either CREATE or ALTER. You can straightaway start the statement as CREATE OR ALTER and SQL Server will handle the rest.

The following example shows the way of using it;

USE AdventureWorks2014;
GO

CREATE OR ALTER VIEW Sales.GetSales
AS
SELECT h.SalesOrderNumber, h.CustomerID, SUM(d.LineTotal) TotalAmount
FROM Sales.SalesOrderHeader h
 INNER JOIN Sales.SalesOrderDetail d
  ON h.SalesOrderID = d.SalesOrderID
GROUP BY h.SalesOrderNumber, h.CustomerID;


No comments:

Post a Comment