1

So we have a script (that was generated from the SQL Schema compare in Visual Studio).

However it's failing on certain ones (because for whatever reason the database upgrade contains constraints that it wasnt supposed to)

So the drop constraints are failing because the constraints don't even exist.

So pretty much this:

ALTER TABLE [dbo].[ZONE] DROP CONSTRAINT [DF_ZONE_EXCLUDE];
GO
ALTER TABLE [dbo].[ZONE_NUMS] DROP CONSTRAINT [DF_ZONE_NUMS_ZONE_WORK];
GO

For example will run the ZONE drop constraint, but will fail on the ZONE_NUMS drop constraint (Saying ZONE_NUMS constraint doesn't exist when it tries to drop). And there are like 500 of these.......all in one big block (produced from the generate upgrade script)

Is there any way for it to continue running instead of stopping the script if it hits on it tries to drop and doesn't exist?

Thanks

mehdi lotfi
  • 11,194
  • 18
  • 82
  • 128
  • 1
    I'm pretty sure it *will* continue running - are you sure it doesn't? – Blorgbeard Jan 08 '14 at 19:28
  • It def. doesn't, complains that the "batch" received errors. "an error occured during execution of batch".. Exiting. is what I get –  Jan 08 '14 at 19:28
  • I just ran that script with a `select 1` added to the end against a DB that doesn't have any tables by those names. I got two errors, but when I switched back to the results tab, I also got my `1` resultset. You're sure the other commands aren't executed? What's the exact error? – Blorgbeard Jan 08 '14 at 19:31
  • Msg 3728, Level 16, State 1, Line 1 'DF_ORDER_CANCEL' is not a constraint. Msg 3727, Level 16, State 0, Line 1 Could not drop constraint. See previous errors. Then it gives the "an error occured during execution of batch etc.... –  Jan 08 '14 at 19:36

1 Answers1

0

You should try this out of you feel that your script is trying to drop a constraint that doesn't exist -

How can I check if a SQL Server constraint exists?

Simply, check the constraint for existence before dropping. Standard practice I believe.

Community
  • 1
  • 1
Suyash Khandwe
  • 386
  • 3
  • 11