With SQL Server 2016 SP1 came a small but helpful new statement to create views: OR ALTER. If you add this to the create script for a view, SQL Server will figure out if it should run the CREATE or the ALTER statement:
1 2 3 4 5 6 7 8 9 10 11 |
CREATE OR ALTER VIEW EmployeeReport AS SELECT p.FirstName, p.MiddleName, p.LastName, e.HireDate, e.JobTitle FROM Person.Person p JOIN HumanResources.Employee e ON p.BusinessEntityID = e.BusinessEntityID |
This feature is especially helpful when you incrementally develop your views. You can focus on the change in the view and do not need to switch between CREATE and ALTER.
For those who do not use SQL Server: You can use OR REPLACE in Postgres or in Oracle to get the same functionality.