Friday, August 14, 2015

How to enable check object existence in Generate Script task from SSMS(SQL Management Studio For SQL Server 2012 and Above

Today i perform a task to script all the change in the QA for production deployment.

when i test the script in the test database which is replicate from live. However i got the following message

Msg 3701, Level 11, State 5, Line 7
Cannot drop the procedure 'dbo.MySp_Sel', because it does not exist or you do not have permission.

The root cause of this issue is that Microsoft set the Check for Object existence to be False by default.



you can reach this window following these steps

choose Options from Tool Menu







Expanded the SQL Server Object Explorer from the left window panel.




Click on the Scripting to show the general scripting options, change the Check for object
existence to be True.




then run the Generate Script Task again, the Check Object Existence shown in the script.

/****** Object:  StoredProcedure [dbo].[MYSp]    Script Date: 8/14/2015 10:24:48 AM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MYSp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MYSp]



Happy Programming.






















No comments:

Post a Comment