Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I m working in VS2012 for a Database project and i am generating deployment scripts for the same.
After generating scripts when i m executing those scripts in SQL Server then it is showing Below error :

ALTER TABLE [dbo].[ARC] DROP CONSTRAINT [DF__ARC__created_dt__2BC97F7C];
Msg 4902, Level 16, State 1, Line 1
Cannot find the object "dbo.ARC" because it does not exist or you do not have permissions.

And when i m using below code it is working fine:
IF EXISTS (SELECT * FROM sysobjects WHERE name =[DF__ARC__created_dt__2BC97F7C];)
BEGIN
ALTER TABLE [dbo].[ARC] DROP CONSTRAINT [DF__ARC__created_dt__2BC97F7C];
END;

I want to generate scripts with "IF EXISTS" option automatically.
Is there any option to generate these scripts with above option automatically.
Please Suggest on the same.
Posted
Updated 5-Dec-13 23:41pm
v2

1 solution

 
Share this answer
 
Comments
rizziansari786 6-Dec-13 7:12am    
Hi,
Thanks for your time. But I m not getting this.
Could you please provide this in detail.
In my Generated script there are large number of SQL statements like this.
I am searching for any option in VS2012, from where directly i could be able to apply "IF EXIST" statement with every SQL statement in entire script.
thatraja 6-Dec-13 7:30am    
Did you read that page fully?
Check this line
/* In SSMS, go to Tools > Options > SQL Server Object Explorer > Scripting and look for the setting “Check for Object Existence” or “Include IF NOT EXISTS clause,” */
rizziansari786 6-Dec-13 8:10am    
Hi,
I did as per your steps but still it is not working.
Throwing same error.

Is there any such option available in Visual studio 2012 while publishing scripts,like u told for SSMS.
thatraja 6-Dec-13 8:22am    
please share more details, 'not working' won't help us. What's the error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900