Little SQL Server Tricks: CREATE OR ALTER Views

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:

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.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.