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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Violation of %ls constraint '%.*ls'. Cannot insert

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 '%.*ls
Basically 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.337
Column_name|Type|Computed|Length|Prec|Scale|Nullable|TrimTrailingBlanks|FixedLenNullInSource|Collation
NUM_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_AS
FEC_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_AS
IND_TRATAMIENTO|varchar|no|1| | |yes|no|no|SQL_Latin1_General_CP1_CI_AS
COD_INTERLOCUTOR|varchar|no|20| | |yes|no|no|SQL_Latin1_General_CP1_CI_AS
TIP_INTER|varchar|no|2| | |yes|no|no|SQL_Latin1_General_CP1_CI_AS
FEC_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_AS
FEC_COMUNICA|datetime|no|8| | |yes|(n/a)|(n/a)|
NOM_USUARORACO|varchar|no|30| | |yes|no|no|SQL_Latin1_General_CP1_CI_AS
COD_ESTADOANT|varchar|no|2| | |yes|no|no|SQL_Latin1_General_CP1_CI_AS
COD_SECTORDESV|numeric|no|5|3 |0 |yes|(n/a)|(n/a)|

Destination table:Name|Owner|Type|Created_datetime
ACA_INCIDENCIA|dbo|user table|2006-12-14 19:03:21.183
Column_name|Type|Computed|Length|Prec|Scale|Nullable|TrimTrailingBlanks|FixedLenNullInSource|Collation
NUM_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_AS
FEC_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_keys
DEFAULT 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, FUENTE

i tried to find out duplicates ftom the source table but it yields no rows:

SELECT NUM_INCIDENCIA
FROM TEMP_ACA_INCIDENCIA
GROUP BY NUM_INCIDENCIA
HAVING count(NUM_INCIDENCIA) > 1

how 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 Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -