In previous versions of Sql Server we use statement like below to drop the stored procedure if exists. Let’s try to re-drop the stored procedure WelcomeMessage which is already dropped.įrom the result it is clear that it will not raise any error if the stored procedure doesn’t exists, it will continue executing the next statement in the batch. If the stored procedure doesn’t exists it will not raise any error, it will continue executing the next statement in the batch. DROP PROCEDURE IF EXISTS dbo.WelcomeMessage In Sql Server 2016 we can write a statement like below to drop a Stored Procedure if exists. How to check if a Stored Procedure exists CREATE DATABASE SqlHintsDemoDBĬREATE TABLE dbo.Customers (Id INT, Name Nvarchar(50)) To demonstrate this clause let us first create a sample Database with a Table and a Stored Procedure. Let us understand this new IF EXISTS clause in the DROP statement with an extensive list of examples. IF EXISTS: It is an optional clause and if it is mentioned in the DROP statement then it checks the existence of the object, if it exists it will drop otherwise continues executing the next statement in the block without raising any issues. WHERE: OBJECT_TYPE like Table, Procedure, View, Function, Database, Trigger, Assembly, Sequence, Index etc. Basically it avoids writing if condition and within if condition writing a statement to check the existence of the object. Basically, it checks the existence of the object, if the object does exists it drops it and if it doesn’t exists it will continue executing the next statement in the batch. In Sql Server 2016, IF EXISTS is the new optional clause introduced in the existing DROP statement.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |