getting an error about a constraint that doesn't exist?
randyv
Posts: 166
I've been using SQL Compare to update tables on an ODS (copy of production database).
Got this error on a table update:
[2714] There is already an object named 'DF_jc-time-sh_emp-id_20080818125445337' in the database.
Could not create constraint. See previous errors.
I'm not quite clear on why I'm getting the error because a check of
INFORMATION_SCHEMA.TABLE_CONSTRAINTS on the target database reveals that this doesn't appear to exist on the target database.
I'm not using SQL Source Control, so the advice of creating a migration script isn't helpful to me.
Any guidance would be appreciated.
Got this error on a table update:
[2714] There is already an object named 'DF_jc-time-sh_emp-id_20080818125445337' in the database.
Could not create constraint. See previous errors.
I'm not quite clear on why I'm getting the error because a check of
INFORMATION_SCHEMA.TABLE_CONSTRAINTS on the target database reveals that this doesn't appear to exist on the target database.
I'm not using SQL Source Control, so the advice of creating a migration script isn't helpful to me.
Any guidance would be appreciated.
What we do in life echoes in eternity <><
Randy Volters
Randy Volters
Comments
Randy Volters
Randy Volters
I dropped the table, then when I try to create it again, I get the same error as reported at the top of the thread.
It is coming from the constraint on the [emp-id] column, but if the table was dropped, how could the object DF_jc-time-sh_emp-id_20080818125445337 still exist? More importantly, how can I drop it?
CREATE TABLE [dbo].[jc-time-sh]
(
[emp-id] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_jc-time-sh_emp-id_20080818125445337] DEFAULT (''),
Randy Volters
:oops:
Randy Volters
Adding constraints to [dbo].[tblMAMSRBHeader]
There is already an object named 'DF__tblMAMSRB__Concu__60FC61CA' in the database.
Could not create constraint. See previous errors.
I look at tblMAMSRBHeader and it does not have a constraint with that name. However, I did find it under a different table with a similar name tblMAMSRBContributions.
Is there a way to tell SQL Compare to just give it a different name if it finds one of the same name already there?
It is very hard to fix this programmically. SQL Server does not let you directly delete records out of the default constraints table (sys.default_constraints). You have to do a ALTER statement on the table. The problem with that is that we don't know what table it is under until the error happens. I have been able to write a query that looks up the table name:
And then I have to see how hard it would be to put that into a drop statement and have that run before the structural comparison. Even if this all works...someone else can call in the next day with a new constraint that's giving them issues and I would have to write a new query with drop for the new constraint name.
There must be a better way!
I added two columns to a table, updated (2) views, (3) procedures to support new columns and I received this on a update from Development to Test.
The following error message was returned from the SQL Server:
There is no table: Docs].[tmp_rg_xx_ContentNodes. I'm guessing this is some work table being used by SQL Compare application.
[2714] There is already an object named 'DF__ContentNo__Activ__53D770D6' in the database.
Could not create constraint. See previous errors.
The following SQL command caused the error:
CREATE TABLE [Docs].[tmp_rg_xx_ContentNodes]
(
[...
[Active] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF__ContentNo__Activ__53D770D6] DEFAULT ('A')
)
The following messages were returned from the SQL Server:
[5701] Changed database context to 'WP3Test'.
[0] Dropping extended properties
If you are not running the generated script against a database that was not part of the original comparison, please let me know, so we can proceed with your support ticket (F0070615) and we can get some more information from you, because it would be unlikely that this problem has the same cause as the one mentioned in this forum topic, and you're having a new, as yet unknown, problem.