Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
alejo46
Posting Yak Master
157 Posts |
Posted - 2014-08-29 : 21:08:08
|
Good evening, i need your help pls, there is a SP and sudenly yield error: Violation of %ls constraint '%.*ls'. Cannot insert duplicate key in object '%.*lsBasically this SP inserts data fron one Ssource table to another:destination table:Source table:TEMP_ACA_INCIDENCIA_SCL|dbo|user table|2010-01-22 19:25:24.337Column_name|Type|Computed|Length|Prec|Scale|Nullable|TrimTrailingBlanks|FixedLenNullInSource|CollationNUM_INCIDENCIA|numeric|no|9|10 |0 |yes|(n/a)|(n/a)|TIP_INTERLOCUTOR|numeric|no|5|2 |0 |yes|(n/a)|(n/a)|TIP_INCIDENCIA|numeric|no|5|5 |0 |yes|(n/a)|(n/a)|NUM_ATENCION|numeric|no|9|10 |0 |yes|(n/a)|(n/a)|NOM_USUARORACR|varchar|no|30| | |yes|no|no|SQL_Latin1_General_CP1_CI_ASFEC_CREACION|datetime|no|8| | |yes|(n/a)|(n/a)|FEC_ESTIMADA|datetime|no|8| | |yes|(n/a)|(n/a)|COD_ESTADO|varchar|no|2| | |yes|no|no|SQL_Latin1_General_CP1_CI_ASIND_TRATAMIENTO|varchar|no|1| | |yes|no|no|SQL_Latin1_General_CP1_CI_ASCOD_INTERLOCUTOR|varchar|no|20| | |yes|no|no|SQL_Latin1_General_CP1_CI_ASTIP_INTER|varchar|no|2| | |yes|no|no|SQL_Latin1_General_CP1_CI_ASFEC_ALARMA|datetime|no|8| | |yes|(n/a)|(n/a)|FEC_REAL|datetime|no|8| | |yes|(n/a)|(n/a)|NOM_USUARORASO|varchar|no|30| | |yes|no|no|SQL_Latin1_General_CP1_CI_ASFEC_COMUNICA|datetime|no|8| | |yes|(n/a)|(n/a)|NOM_USUARORACO|varchar|no|30| | |yes|no|no|SQL_Latin1_General_CP1_CI_ASCOD_ESTADOANT|varchar|no|2| | |yes|no|no|SQL_Latin1_General_CP1_CI_ASCOD_SECTORDESV|numeric|no|5|3 |0 |yes|(n/a)|(n/a)|Destination table:Name|Owner|Type|Created_datetimeACA_INCIDENCIA|dbo|user table|2006-12-14 19:03:21.183Column_name|Type|Computed|Length|Prec|Scale|Nullable|TrimTrailingBlanks|FixedLenNullInSource|CollationNUM_INCIDENCIA|int|no|4|10 |0 |no|(n/a)|(n/a)|TIP_INTERLOCUTOR|smallint|no|2|5 |0 |no|(n/a)|(n/a)|TIP_INCIDENCIA|int|no|4|10 |0 |no|(n/a)|(n/a)|NUM_ATENCION|int|no|4|10 |0 |no|(n/a)|(n/a)|NOM_USUARORACR|varchar|no|30| | |no|no|no|SQL_Latin1_General_CP1_CI_ASFEC_CREACION|datetime|no|8| | |no|(n/a)|(n/a)|FEC_ESTIMADA|datetime|no|8| | |no|(n/a)|(n/a)|PK_ACA_INCIDENCIA|nonclustered, unique, primary key located on INDICES|NUM_INCIDENCIA, FUENTE constraint_type|constraint_name|delete_action|update_action|status_enabled|status_for_replication|constraint_keysDEFAULT on column FUENTE|DF_ACA_INCIDENCIA_FUENTE|(n/a)|(n/a)|(n/a)|(n/a)|(0)PRIMARY KEY (non-clustered)|PK_ACA_INCIDENCIA|(n/a)|(n/a)|(n/a)|(n/a)|NUM_INCIDENCIA, FUENTEi tried to find out duplicates ftom the source table but it yields no rows:SELECT NUM_INCIDENCIAFROM TEMP_ACA_INCIDENCIAGROUP BY NUM_INCIDENCIAHAVING count(NUM_INCIDENCIA) > 1how do i start and getaround this ?THanks for your help in advanced |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-09-02 : 15:36:47
|
I can't read the DDL like that. Please post the CREATE TABLE/ALTER TABLE statements for both tables, including primary key and any unique constraints.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
jeffw8713
Aged Yak Warrior
819 Posts |
Posted - 2014-09-03 : 14:09:25
|
It is not necessarily a duplicate in the source table - rather, it will be something in the source table that already exists in the destination table. It could also be how the query pulling data from the source table is constructed - where it could be creating duplicate rows for insertion into the destination.To be able to help further, we would need the DDL as Tara has requested - as well as the actual code being used. |
|
|
|
|
|