Creating or Altering an Objects with a Single Statement | Database Journal

Creating or Altering an Objects with a Single Statement

Written By
Gregory Larsen
Gregory Larsen
Apr 6, 2020
1 minute read

Do you get tired of having your CREATE PROCEDURE statement failing if the stored procedure already exists? If you are like me then you probably hate this as much as I do. I get tired of writing a drop then create statement like below:

IF OBJECT_ID('dbo.YourObject','U') IS NOT NULL
DROP PROCEDURE dbo.YourObject;
CREATE PROCEDURE dbo.YourObject AS _

Or modifying my CREATE PROCEDURE statement to be an ALTER PROCEDURE after my initial creation.  Well now there is a better way.

With the introduction of SQL Server 2016 SP1 Microsoft introduced the CREATE OR ALTER statement. Yes, you read that right the “CREATE OR ALTER” statement. This is not two statements; it is just a single statement. If the object doesn’t exist it will create it. If the object does exist it will alter it. This statement works on stored procedures, views, functions, and triggers. If you are running SQL Server 2016 SP1 or above, you can now create or alter a stored procedure using a statement similar to below.

CREATE OR ALTER PROCEDURE dbo.YourObject AS _

# # #

» See All Articles by Columnist Gregory A. Larsen

Gregory Larsen

Gregory A. Larsen is a DBA at Washington State Department of Health (DOH). Greg is responsible for maintaining SQL Server and other database management software. Greg works with customers and developers to design and implement database changes, and solve database/application related problems. Greg builds homegrown solutions to simplify and streamline common database management tasks, such as capacity management.

Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.