Composite key constraint in SSIS
Hi All,
I have created one SSIS package to move data from one table to another table in same database using oledb connection.Now I want to enforce composite key constraint while moving data as follows:
Table A has following contents :
Col1 col2 col3
1 a b
2 c d
3 a b
So,while moving data, i want to verify the contents of col2 and col3(col2+col3) ie,composite key made of col2 and col3.In this case i want to move data of row 2 only and data of row 1 and 3 will go to error log file.
I am trying to use lookup here but no luck yet. Can anybody help me to achieve this .
Thanks in advance,
Sanket
Hi Sanket,
I do agree with Visakh approach if table reside on same server, why go for the SSIS. But If you still want to do it, here are steps(It bit complex for simple operation like this, i didn't find
any other approach). I am using same table structure as mentioned above:
create table sampletest
col1 int ,
col2 varchar(10),
col3 varchar(10)
GO
insert into sampletest
values (1,'a','b'),(2,'c','d'),(3,'a','b')
1.) Load the
Data from source with all columns.
2.) Place an Aggregate
Task .Here is configuration:
Column
Operation
Col1
Max/Min
Col2
Group by
Col3
Group by
(*) - Output Alias (say cnt)
Count All
Figure 1:
3.) Place a condition split. With expression
(DT_I4)Cnt == 1
2.)
Move case1 to destination table and other conditional split to error table.
Full Diagram:
Regards Harsh
Similar Messages
-
Hi,
I am providing support to one of our clients, where we have jobs scheduled to load the data from the tables in the source database to the destination database via SSIS packages. The first time load is a full load where we truncate all the tables in the destination
and load them from the source tables. But from the next day, we perform the incremental load from source to destination, i.e., only modified records fetched using changed tracking concept will be loaded to the destination. After full load, if we run the incremental
load, the job is failing with the error on one of the packages "Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object '<tablename>'. The duplicate key value is <1234>, even though there are no duplicate records. When we
try debugging and running the failing package, it runs successfully. We are not able to figure out why the package fails and when we run the next day it runs successfully. Request you to help me in this regard.
Thank you,
Bala Murali Krishna Medipally.Hi,
I am providing support to one of our clients, where we have jobs scheduled to load the data from the tables in the source database to the destination database via SSIS packages. The first time load is a full load where we truncate all the tables in the destination
and load them from the source tables. But from the next day, we perform the incremental load from source to destination, i.e., only modified records fetched using changed tracking concept will be loaded to the destination. After full load, if we run the incremental
load, the job is failing with the error on one of the packages "Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object '<tablename>'. The duplicate key value is <1234>, even though there are no duplicate records. When we
try debugging and running the failing package, it runs successfully. We are not able to figure out why the package fails and when we run the next day it runs successfully. Request you to help me in this regard.
Thank you,
Bala Murali Krishna Medipally.
I suspect you are trying to insert modified records instead of updating. -
Composite unique constraint on parent and child values?
Is it possible to have a composite unique constraint containing values from child elements? The below example has the 'child' elements are out-of-line but this is preferred but optional, as I know you cannot have a unique constraint across tables without having a reference table containing the constraint and both columns. How does xdb handle this requirement?
allowed:
<parent ID="1">
<child><name>test1</name></child>
<child><name>test2</name></child>
</parent>
<parent ID="2">
<child><name>test1</name></child>
<child><name>test2</name></child>
</parent>not allowed:
<parent ID="1">
<child><name>test1</name></child>
<child><name>test1</name></child>
</parent>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xdb="http://xmlns.oracle.com/xdb"
xdb:storeVarrayAsTable="true"
elementFormDefault="qualified">
<xs:element name="parent" type="Parent_T"
xdb:columnProps="CONSTRAINT parent_pkey PRIMARY KEY (XMLDATA.ID)"
xdb:defaultTable="PARENT"/>
<xs:complexType name="Parent_T" xdb:SQLType="PARENT_T" xdb:maintainDOM="false">
<xs:sequence>
<xs:element name="child" type="Child_T" minOccurs="1" maxOccurs="unbounded" xdb:SQLName="CHILD"
xdb:SQLInline="false" xdb:defaultTable="CHILD" "/>
</xs:sequence>
<xs:attribute name="ID" xdb:SQLName="ID" use="required" />
</xs:complexType>
<xs:complexType name="Child_T" xdb:SQLType="CHILD_T">
<xs:sequence>
<xs:element name="name" type="xs:string" xdb:SQLName="NAME"/>
</xs:sequence>
</xs:complexType>
</xs:schema>xdb:columnProps="CONSTRAINT parent_pkey PRIMARY KEY (XMLDATA.ID),*UNIQUE(XMLDATA.CHILD.NAME)*" raises nonexistant attribute
One possible solution would be to copy the value of the parent primary key to the child element, then I could create a composite unique constraint using only values from the child. However, I have this same requirement elsewhere in my schema nested further down, and it may become messy / bad design having to cascade all the primary keys down the schema. For example I have a recursive element in which two attributes need to be unique only within the parent:
<parent id="1">
<child a="1" b="1">
<child a="1" b="2">
<child a="1" b="1" /> *not allowed
</child>
</child>
<child a="1" b="2" /> *not allowed
</parent>Possible fix:
<child a="1" b="2" parent_id="1" />
<xs:complexType name="Child_T>
<xs:sequence>
<xs:element name="child" xsd:SQLInline="false" xsd:columnProps="UNIQUE(XMLDATA.a,XMLDATA.b,XMLDATA.parent_id)" minOccurs="0" maxOccurs="unbounded" type="Child_T">
</xs:sequence>
</xs:element
</xs:complexType>Is there a better design?
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - ProductionYou can do something like this :
SQL> DECLARE
2
3 xsd_doc xmltype := xmltype('<?xml version="1.0" encoding="utf-8"?>
4 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb">
5 <xs:element name="name" xdb:SQLType="VARCHAR2">
6 <xs:simpleType>
7 <xs:restriction base="xs:string">
8 <xs:maxLength value="30"/>
9 </xs:restriction>
10 </xs:simpleType>
11 </xs:element>
12 <xs:element name="child" xdb:SQLType="CHILD_T">
13 <xs:complexType xdb:SQLType="CHILD_T" xdb:maintainDOM="false">
14 <xs:sequence>
15 <xs:element ref="name"/>
16 </xs:sequence>
17 </xs:complexType>
18 </xs:element>
19 <xs:element name="parent" xdb:SQLType="PARENT_T">
20 <xs:complexType xdb:SQLType="PARENT_T" xdb:maintainDOM="false">
21 <xs:sequence>
22 <xs:element ref="child" maxOccurs="unbounded" xdb:SQLCollType="CHILD_COLL"/>
23 </xs:sequence>
24 <xs:attribute name="ID" type="xs:integer" use="required"/>
25 </xs:complexType>
26 </xs:element>
27 <xs:element name="root" xdb:defaultTable="MY_XML_TABLE" xdb:SQLType="ROOT_T">
28 <xs:complexType xdb:SQLType="ROOT_T" xdb:maintainDOM="false">
29 <xs:sequence>
30 <xs:element ref="parent" maxOccurs="unbounded" xdb:SQLCollType="PARENT_COLL"/>
31 </xs:sequence>
32 </xs:complexType>
33 </xs:element>
34 </xs:schema>');
35
36 BEGIN
37
38 dbms_xmlschema.registerSchema(
39 schemaURL => 'test_parent.xsd',
40 schemaDoc => xsd_doc,
41 local => true,
42 genTypes => true,
43 genbean => false,
44 genTables => false,
45 enableHierarchy => dbms_xmlschema.ENABLE_HIERARCHY_NONE
46 );
47
48 END;
49 /
PL/SQL procedure successfully completed
SQL> CREATE TABLE my_xml_table OF XMLTYPE
2 XMLTYPE STORE AS OBJECT RELATIONAL
3 XMLSCHEMA "test_parent.xsd"
4 ELEMENT "root"
5 VARRAY xmldata."parent" STORE AS TABLE my_parent_tab
6 (
7 VARRAY "child" STORE AS TABLE my_child_tab
8 )
9 ;
Table created
SQL> ALTER TABLE my_parent_tab ADD CONSTRAINT parent_uk UNIQUE (nested_table_id, "ID");
Table altered
SQL> ALTER TABLE my_child_tab ADD CONSTRAINT child_uk UNIQUE (nested_table_id, "name");
Table altered
Then :
SQL> insert into my_xml_table values (
2 xmltype('<root><parent ID="1">
3 <child><name>test1</name></child>
4 <child><name>test2</name></child>
5 </parent>
6 <parent ID="1">
7 <child><name>test1</name></child>
8 <child><name>test2</name></child>
9 </parent></root>')
10 );
insert into my_xml_table values (
ERREUR à la ligne 1 :
ORA-00001: violation de contrainte unique (DEV.PARENT_UK)
SQL> insert into my_xml_table values (
2 xmltype('<root><parent ID="1">
3 <child><name>test1</name></child>
4 <child><name>test1</name></child>
5 </parent>
6 <parent ID="2">
7 <child><name>test1</name></child>
8 <child><name>test2</name></child>
9 </parent></root>')
10 );
insert into my_xml_table values (
ERREUR à la ligne 1 :
ORA-00001: violation de contrainte unique (DEV.CHILD_UK)
SQL> insert into my_xml_table values (
2 xmltype('<root><parent ID="1">
3 <child><name>test1</name></child>
4 <child><name>test2</name></child>
5 </parent>
6 <parent ID="2">
7 <child><name>test1</name></child>
8 <child><name>test2</name></child>
9 </parent></root>')
10 );
1 ligne créée.http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14259/xdb06stt.htm#sthref987 -
Foreign key constraint on multi-column primary key accepts 1 empty column!?
Hi, we have a reference table with a two-column primary key. In the child table there is a non-mandatory foreign key constraint to this table. So if both child columns are null it's ok too. But now we see that if one of the two child table columns that build up the foreign key is null, the other column can have any (non-existant in the master-tabel) value you like!? That does not make sense.
Can anyone explain this to me???
Regards, Paul.Paul, I believe that this is in accordance to the ANSI SQL standard requirement for the treatment of nulls in a multi-column FK. In any case Oracle specifically states this is the way FK work From the 10 Concepts manual, Ch 21 Data Integrity, topic Nulls and Foreign Keys:
The relational model permits the value of foreign keys either to match the referenced primary or unique key value, or be null. If any column of a composite foreign key is null, then the non-null portions of the key do not have to match any corresponding portion of a parent key. <<HTH -- Mark D Powell -- -
Violation of PRIMARY KEY constraint
Hello,
I have the following table in my oracle database :
create table FLTRPTDATA
esn VARCHAR2(10) default 'ALL' not null,
periodid NUMBER not null,
yearid NUMBER default 2007 not null,
reportid NUMBER not null,
entryid NUMBER not null,
operatorid VARCHAR2(30) default 'XXX' not null,
param1 VARCHAR2(200),
param2 VARCHAR2(200),
param3 VARCHAR2(200),
param4 VARCHAR2(200),
param5 VARCHAR2(200),
param6 VARCHAR2(200),
param7 VARCHAR2(200),
param8 VARCHAR2(200),
param9 VARCHAR2(200),
param10 VARCHAR2(200),
acid VARCHAR2(8) default 'ALL' not null
and also have a composite primary key for the table as follows :
add constraint PK_FLTRPTDATA primary key (ESN, PERIODID, YEARID, REPORTID, ENTRYID, OPERATORID, ACID)
using index
So I expect that I can only insert a new row into the table if the combination of values for ESN,PERIODID,YEARID,REPORTID,ENTRYID,OPERATORID and ACID are unique.
I am running some software that inserts new rows into the table (via an INSERT SQL statement).
When the software runs, it inserts a certain number of rows, but then stops when inserting one of the rows with a Violation of PRIMARY KEY constraint 'PK_FLTRPTDATA'. Cannot insert duplicate key in object 'fltRPTDATA' error.
This implies that the row being inserted contains values for the composite key columns that are NOT unique. However, when I look at the data it fails to insert, I can see that there are NO rows in the table for this combination of column values.
If I then try to MANUALLY insert the same row myself (via my own SQL statement in SQL Developer), the row is inserted with no error.
When I run the software, the first thing it does is delete any rows in the table that it will subsequently insert, so there cannot be any duplicate entries in the table before the inserts take place. I have run the SQL statement that does the deletion myself manually, and it does delete all of the relevant rows.
I have checked the code (I am not the author), and I cannot see anything that would cause the same INSERT to be executed twice.
I have checked the log file generated by the software, and the INSERT is only attempted once (according to the log).
I don't understand why the insert fails when I run the software, and I am wondering if anyone can shed any light on the issue? Has anyone seen this scenario before where you get a PRIMARY KEY constraint violation on a composite key, where the data being inserted IS unique?
Thanks for any help and apologies if this is in the wrong forum,
Jason.>
I don't understand why the insert fails when I run the software, and I am wondering if anyone can shed any light on the issue? Has anyone seen this scenario before where you get a PRIMARY KEY constraint violation on a composite key, where the data being inserted IS unique?
>
One way to find those records would be to create and use a dml error log table. Then those records would get logged to the log table and would not prevent the insert of the valid records.
See Loading Tables in the DBA Guide
http://docs.oracle.com/cd/E11882_01/server.112/e17120/tables004.htm#InsertDMLErrorLogging
Then you can examine the records in the log table and see why they were rejected. -
Table A is a parent of Table B, where Table B really only serves as an intermediary table associating Table A's records with some Table C (also a parent of table B).
As such, Table B is FK'd as a child of both Tables A & C. In order to delete records from Table A, a subquery against table B must be performed (relating table A and table C's fields).
So my task is to purge certain records from this schema based on the composite key in table C.
This is the order I have to go in because of the key constraints:
Delete From table B
Delete From table A
Delete From table C
However, in order to delete from table A, its children rows in record B must be accessed because the entire deletion stems off a subquery select with a composite key from table C (which must then be translated through table B to get to the correct records in table A)
Naturally, the DBAs didn't enable cascade delete anywhere in this entire schema (sigh). I have no ability to change anything about the database, and because of a number of concerns, I can't write to a temp table and I can't pull anything at all into the executing program's memory.
Is there anyway to do this. (Sorry if Table A/B/C is confusing. I can give them real names later)Hi,
Have a look at this sample:
This code
drop table transaction cascade constraints;
drop table Invoice cascade constraints;
drop table Invoice_Transaction cascade constraints;
create table Transaction
ID_ NUMBER,
LBL_T VARCHAR2(50 CHAR)
create table Invoice
ID_ NUMBER,
LVL_I VARCHAR2(50)
create table Invoice_Transaction
ID_TRANSACTION NUMBER,
ID_INVOICE NUMBER
alter table transaction add constraint t_pk primary key(id_);
alter table invoice add constraint i_pk primary key(id_);
alter table Invoice_Transaction add constraint it_pk primary key(id_transaction,id_invoice);
alter table Invoice_Transaction add constraint it_t foreign key (id_transaction) references transaction(id_);
alter table Invoice_Transaction add constraint it_i foreign key (id_invoice) references invoice(id_);
insert into transaction values (1,'NA1');
insert into transaction values (2,'NA2');
insert into invoice values (1,'I1');
insert into invoice values (2,'I2');
insert into invoice values (3,'I3');
insert into invoice values (4,'I4');
insert into invoice_transaction values (1,1);
insert into invoice_transaction values (1,2);
insert into invoice_transaction values (1,3);
insert into invoice_transaction values (2,4);
commit;
select lbl_t, lvl_i
from transaction t, invoice i, invoice_transaction it
where t.id_ = it.id_transaction
and i.id_ = it.id_invoice;
create or replace procedure remove_transaction(pIdTrans IN NUMBER)
IS
CURSOR cInvTrans IS
SELECT id_invoice
FROM Invoice_Transaction
WHERE id_transaction = pIdTrans
FOR UPDATE;
BEGIN
FOR vInvTrans IN cInvTrans
LOOP
DELETE FROM Invoice_Transaction WHERE CURRENT OF cInvTrans;
DELETE FROM invoice WHERE id_ = vInvTrans.id_invoice;
END LOOP;
DELETE FROM TRANSACTION WHERE ID_ = pIdTrans;
COMMIT;
END;
CALL remove_transaction(1);
select lbl_t, lvl_i
from transaction t, invoice i, invoice_transaction it
where t.id_ = it.id_transaction
and i.id_ = it.id_invoice;
Generates this output
drop table transaction succeeded.
drop table Invoice succeeded.
drop table Invoice_Transaction succeeded.
create table succeeded.
create table succeeded.
create table succeeded.
alter table transaction succeeded.
alter table invoice succeeded.
alter table Invoice_Transaction succeeded.
alter table Invoice_Transaction succeeded.
alter table Invoice_Transaction succeeded.
1 rows inserted
1 rows inserted
1 rows inserted
1 rows inserted
1 rows inserted
1 rows inserted
1 rows inserted
1 rows inserted
1 rows inserted
1 rows inserted
commit succeeded.
LBL_T LVL_I
NA1 I1
NA1 I2
NA1 I3
NA2 I4
4 rows selected
procedure remove_transaction(pIdTrans Compiled.
CALL remove_transaction(1) succeeded.
LBL_T LVL_I
NA2 I4
1 rows selectedHTH!
Yoann. -
Is it possible to create foreign key from composite key in other table.
SQL> desc PRODUCT_CONFIG_OPTION;
Name Null? Type
CONFIG_ITEM_ID NOT NULL VARCHAR2(20) --composite primary key
CONFIG_OPTION_ID NOT NULL VARCHAR2(20) --composite primary key
CONFIG_OPTION_NAME VARCHAR2(100)
DESCRIPTION VARCHAR2(255)
SEQUENCE_NUM NUMBER(18)
LAST_UPDATED_STAMP TIMESTAMP(6)
LAST_UPDATED_TX_STAMP TIMESTAMP(6)
CREATED_STAMP TIMESTAMP(6)
CREATED_TX_STAMP TIMESTAMP(6)
SQL> DESC PRODUCT_CONFIG_ITEM;
Name Null? Type
CONFIG_ITEM_ID NOT NULL VARCHAR2(20)
CONFIG_ITEM_TYPE_ID VARCHAR2(20)
CONFIG_ITEM_NAME VARCHAR2(100)
DESCRIPTION VARCHAR2(255)
LONG_DESCRIPTION CLOB
IMAGE_URL VARCHAR2(255)
LAST_UPDATED_STAMP TIMESTAMP(6)
LAST_UPDATED_TX_STAMP TIMESTAMP(6)
CREATED_STAMP TIMESTAMP(6)
CREATED_TX_STAMP TIMESTAMP(6)
SQL> desc product;
Name Null? Type
PRODUCT_ID NOT NULL VARCHAR2(20)
PRODUCT_TYPE_ID VARCHAR2(20)
PRIMARY_PRODUCT_CATEGORY_ID VARCHAR2(20)
MANUFACTURER_PARTY_ID VARCHAR2(20)
FACILITY_ID VARCHAR2(20)
INTRODUCTION_DATE TIMESTAMP(6)
SUPPORT_DISCONTINUATION_DATE TIMESTAMP(6)
SALES_DISCONTINUATION_DATE TIMESTAMP(6)
SALES_DISC_WHEN_NOT_AVAIL CHAR(1)
INTERNAL_NAME VARCHAR2(255)
BRAND_NAME VARCHAR2(100)
COMMENTS VARCHAR2(255)
=========
CREATE TABLE PROD_CONFIG_PROD_CONFIG_OPTION (
PRODUCT_ID VARCHAR2(20),
CONFIG_ITEM_ID VARCHAR2(20),
CONFIG_OPTION_ID VARCHAR2(20),
PAGE_NUM_TO NUMBER(18),
ALTERNATE_PAGE_NUM_TO1 NUMBER(18),
ALTERNATE_PAGE_NUM_TO2 NUMBER(18),
ALTERNATE_PAGE_NUM_TO3 NUMBER(18),
LAST_UPDATED_STAMP TIMESTAMP(6),
LAST_UPDATED_TX_STAMP TIMESTAMP(6),
CREATED_STAMP TIMESTAMP(6),
CREATED_TX_STAMP TIMESTAMP(6),
CONSTRAINT PK_PROD_CAT_CONFIG_MOD PRIMARY KEY (PRODUCT_ID),
CONSTRAINT FK_PRODUCT_ID FOREIGN KEY (PRODUCT_ID) REFERENCES PRODUCT(PRODUCT_ID),
CONSTRAINT FK_CONFIG_ITEM_ID FOREIGN KEY (CONFIG_ITEM_ID) REFERENCES PRODUCT_CONFIG_ITEM(CONFIG_ITEM_ID),
CONSTRAINT FK_CONFIG_OPTION_ID FOREIGN KEY (CONFIG_OPTION_ID) REFERENCES PRODUCT_CONFIG_OPTION(CONFIG_OPTION_ID) )
TABLESPACE DATA_SMALL
i try to create this table if i omit 3rd foreign key constraint then table successfully created.but including trd foreign key constraint it return error "ORA-02270: no matching unique or primary key for this column-list"
i checked everything is it possible to create foreign key from composite key in other table.And
CONSTRAINT FK_CONFIG_OPTION_ID FOREIGN KEY (CONFIG_ITEM_ID,CONFIG_OPTION_ID) REFERENCES PRODUCT_CONFIG_OPTION(CONFIG_ITEM_ID,CONFIG_OPTION_ID)
? -
Can we have more than one primary key constraint to a Oracle Table?
Hi,
Can we have more than one primary keys to a single table in oracle? ( Not the composite key)
Please somebody answer..
Regards,
Alaka811935 wrote:
Can we have more than one primary keys to a single table in oracle? ( Not the composite key)
In principle a table can have multiple keys if you need them. It is a very strong convention that just one of those keys is designated to be "primary" but that's just a convention and it doesn't stop you implementing other keys as well.
Oracle provides two uniqueness constraints for creating keys: the PRIMARY KEY constraint and the UNIQUE constraint. The PRIMARY KEY constraint can only be used once per table whereas the UNIQUE constraint can be used multiple times. Other than that the PRIMARY KEY and UNIQUE constraints serve the same function (always assuming the column(s) they are applied to are NOT NULL). -
Composite Key Validation in EOImpl
Hello,
Please anyone can give example of how to validate composite key validation?
I have tried by following in EOImpl code but its not working:
OADBTransaction transaction = getOADBTransaction();
Object[] ItemKey = {getOrganizationId(),getUserId(),getProcess()};
EntityDefImpl def = XxEOImpl.getDefinitionObject();
XxEOImpl item_name = (XxEOImpl)def.findByPrimaryKey(getOADBTransaction(),new Key(ItemKey));
if (item_name != null)
throw new OAException("Erorr duplicate");
Please suggest its urgent..
Thanks,
Swati ThakkarHello Gurus,
Can you please suggest the following way of validation is correct or not!?
We have defined primary key on 3 attributes as a composite key, created EO and VO.
Now to add new row we are asking values from user using LOV values.
is the handling of unique value constraint using TooManyObjects Exception valid approach to handle error?
EOImpl Code:
try {
setAttributeInternal(PROCESSTYPE, value);
} catch (TooManyObjectsException toomany) {
throw new OAException("Value is already exist.");
Please suggest the right approach to handling Composite key validation..
Thanks,
Swati -
Getting ddl of primary key constraint
Hi
I want to drop a primary key index,
I think, In order to do that I want to drop primary key constraint.
When I get the ddl of the primary key index, it is like
CREATE UNIQUE INDEX "NI"."PREM_PK" ON "NI"."PREM" ("BRANCH_ID", "PRODUCT", "COMPANY_ID","SUM_SEQNO")
I dont undertand why there are more than 1 columns.
As far as I know primary key should be in one column.
How can I get the ddl of primary key constraint? I am little bit confusedIt is perfectly legal for a primary key to be defined on a combination of different columns-- this is a composite primary key. I would generally prefer to create a new column populated by a sequence and declare that column to be the primary key rather than having a 4 column composite primary key, particularly if there is any possibility that there would ever be child tables to this table. But it is perfectly legal to have a 4 column composite primary key.
Justin -
Violation of PRIMARY KEY constraint . Cannot insert duplicate key in object
hi i am using SQL Server, when i try to insert data from my jsp page it is inserting the data double time and when i try to submit for second time it is showing the following error.
Violation of PRIMARY KEY constraint 'PK_EMPLOYEE'. Cannot insert duplicate key in object 'EMPLOYEE'.
I didnt set identity for primary key. If i try to set identity to true then it is allowing data to submit only if i uncheck my primary key column in cached row set. And if i uncheck that primary key element then i can not retrieve the data by edit button. So how to solve this problem.
Please any help would be appreciated.
Thank You in Advance.Hi,
I am providing support to one of our clients, where we have jobs scheduled to load the data from the tables in the source database to the destination database via SSIS packages. The first time load is a full load where we truncate all the tables in the destination
and load them from the source tables. But from the next day, we perform the incremental load from source to destination, i.e., only modified records fetched using changed tracking concept will be loaded to the destination. After full load, if we run the incremental
load, the job is failing with the error on one of the packages "Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object '<tablename>'. The duplicate key value is <1234>, even though there are no duplicate records. When we
try debugging and running the failing package, it runs successfully. We are not able to figure out why the package fails and when we run the next day it runs successfully. Request you to help me in this regard.
Thank you,
Bala Murali Krishna Medipally.
I suspect you are trying to insert modified records instead of updating. -
Large table, primary key constraint
I have migrated a table from 8i to 9i that is over 300 million rows. I migrated the the table to a 9i database without constraints or indexes.
I have successfully created a composite index of two columns, t1 varchar2(512), t2 varchar2(32). This index took nearly 16 hours to create.
I am now trying to create a primary key based on that index with the following sql:
alter table table1
add constraint table1_t1_t2_pk primary key(t1,t2)
using index table1_t1_t2_idx
nologging
This process has taken over 24 hours and is well into the second day. Studio reports it will take an additional 15 hours to create.
My questions are these?
1. Is my syntax okay?
2. I thought that by creating a primary key on an existing index, that another index is not being created. I thought it would be faster this way. Why is it taking a lot longer to create then the index it is based upon?
3. Is there a more efficient method (other than parallel query) to create this index/constraint on such a large table? What happens when I go production and need to recreate this index if I have a failure. I have never had to do this before. I can't be down for 48 hours to create an index. What other alternatives do I have?
The table is partit[i]Long postings are being truncated to ~1 kB at this time.Is INDEX table1_t1_t2_idx UNIQUE? If it's not that might explain why building the primary key constraint takes longer.
I think the USING INDEX clause with an existing index is intended mainly for different UNIQUE constraints to share the same index. In your situation I think you would be better off just building the primary key constraint.
Cheers, APC -
Altering Primary Key Constraint
hi this may sound silly .
but is it possible to alter a primary key constraint and add another column to it ?
eg. >desc t1
c1 number(3) not null
c2 number(3)
here I have created primary key on column c1.
Now I want to alter this constraint and add second column also as part of primary key constraint (so that it will be composite primary key )
How do i do that ? Do the column needs to be empty ?
ThanksYou should use ALTER TABLE DROP CONSTRAINT / ADD CONSTRAINT option.
Do the column needs to be empty ?Because primary key constraint supposes NOT NULL constraints for columns
included into primary key, all columns havn't to have nulls values (NOT NULL constraint will be added to c2 column):
SQL> create table t1 (c1 number(3) not null, c2 number(3));
Table created.
SQL> alter table t1 add constraint t1_pk primary key(c1);
Table altered.
SQL> insert into t1 values(1,1);
1 row created.
SQL> insert into t1 values(2,null);
1 row created.
SQL> commit;
Commit complete.
SQL> alter table t1 drop constraint t1_pk;
Table altered.
SQL> alter table t1 add constraint t1_pk primary key (c1,c2);
alter table t1 add constraint t1_pk primary key (c1,c2)
ERROR at line 1:
ORA-01449: column contains NULL values; cannot alter to NOT NULL
SQL> update t1 set c2 = 3;
2 rows updated.
SQL> alter table t1 add constraint t1_pk primary key (c1,c2);
Table altered.
SQL> desc t1
Name Null? Type
C1 NOT NULL NUMBER(3)
C2 NOT NULL NUMBER(3)Rgds. -
HowTo: construct Composite key using other composite key?
Hello. I don' undestand how is it possible to do.
Please, see my code:
@Entity
@Table(name = "Person", schema = SCHEMA)
public class Person {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
private String medialogyUid;
private String firstName;
private String lastName;
private String patronymic;
private String biography;
@Entity
@IdClass(Convocation.PK.class)
@Table(name = "Convocation", schema = SCHEMA)
public class Convocation {
@Id
private int number;
@Id
@ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.MERGE, CascadeType.REFRESH, CascadeType.PERSIST})
private Institution institution;
private Date beginDate;
private Date endDate;
public Convocation(){
public Convocation(Institution inst, int number, Date beginDate, Date endDate){
this.institution = inst;
this.number = number;
this.beginDate = beginDate;
this.endDate = endDate;
public static final class PK implements Serializable {
public int number;
public int institution;
public PK(){
/**@param number is convocation,number
* @param institution is convocation.institution.id
public PK(int number, int institution){
this.number = number;
this.institution = institution;
@Override
public boolean equals(Object o) {
if (!(o instanceof PK))
return false;
PK oPK = (PK)o;
return this.number == oPK.number && this.institution == oPK.institution;
@Override
public int hashCode() {
return ((number == 0) ? 0 : new Integer(number).hashCode()) ^ ((institution == 0) ? 0 : new Integer(institution).hashCode());
//And finally the last class:
@Entity
@IdClass(DeputyMandate.PK.class)
@Table(name = "DeputyMandate", schema = SCHEMA)
public class DeputyMandate {
@Id
@ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.MERGE, CascadeType.REFRESH, CascadeType.PERSIST})
private Person person;
@Id
@ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.MERGE, CascadeType.REFRESH, CascadeType.PERSIST})
private Convocation convocation;
private Date dateIn;
private Date dateOut;
public static final class PK implements Serializable {
//don't know what to use @Embeddable or what?
}I want DeputyMandate to use composite key. This composite key is based on Person with simple key +(int id)+ and Convocation PK.
Please, tell me how can I make composite key DeputyMandate.PK using simple key from Person and composite key from Convocation.
Edited by: Holod on 27.08.2008 15:52And
CONSTRAINT FK_CONFIG_OPTION_ID FOREIGN KEY (CONFIG_ITEM_ID,CONFIG_OPTION_ID) REFERENCES PRODUCT_CONFIG_OPTION(CONFIG_ITEM_ID,CONFIG_OPTION_ID)
? -
Create a materized view without primary key constraint on the base table?
Hi
I tried to create a materized view but I got this error:
SQL> CREATE MATERIALIZED VIEW TABLE1_MV REFRESH FAST
START WITH
to_date('04-25-2009 03:00:13','MM-dd-yyyy hh24:mi:ss')
NEXT
sysdate + 1
AS
select * from TABLE1@remote_db
SQL> /
CREATE MATERIALIZED VIEW TABLE1_MV REFRESH FAST
ERROR at line 1:
ORA-12014: table 'TABLE1' does not contain a primary key constraint.
TABLE1 in remote_db doesn't have a primary key constraint. Is there anyway that I can create a materized view on a base table which doesn't have a primary key constraint?
Thanks
LizHi,
Thanks for your helpful info. I created a materialized view in the source db with rowid:
SQL> CREATE MATERIALIZED VIEW log on TABLE1 with rowid;
Materialized view log created.
Then I created a MV on the target DB:
CREATE MATERIALIZED VIEW my_schema.TABLE1_MV
REFRESH FAST
with rowid
START WITH
to_date('04-25-2009 03:00:13','MM-dd-yyyy hh24:mi:ss')
NEXT
sysdate + 1
AS
select * from TABLE1@remote_db
SQL> /
CREATE MATERIALIZED VIEW my_schema.TABLE1_MV
ERROR at line 1:
ORA-12018: following error encountered during code generation for
"my_schema"."TABLE1_MV"
ORA-00942: table or view does not exist
TABLE1 exists in remote_db:
SQL> select count(*) from TABLE1@remote_db;
COUNT(*)
9034459
Any clue what is wrong?
Thanks
Liz
Maybe you are looking for
-
Hi All: I need help...lol I have used Firefox for about 8 years now with NO problems, now I have a new Toshiba and I cannot get Firefox to work smoothly. I am using Windows 7. I do not know how to initialize the application's security component. Many
-
How to fix a corrupt QuickTime file?
Hey all, Today I recorded all of our church services via iMovie (one long 4 hour clip), as I have been doing for more than a month now. However, the guy running the camera turned the camera off before I told iMovie to stop importing, so iMovie litera
-
How to display html form information
I know you can create an html form where visitors can input data and that data can then be sent to the specified email address. But I am wondering, is it possible to have this data that they enter create and displayed on a new page in a specified lay
-
I am trying to see the changes done on KONP - Pricng table. In CDHDR what will be the Object value for this KONP table. WHen i put the table name and field name in CDPOS, it is not giving me any details In short i am trying to see the changed done in
-
ASM: cannot create asm disks - permission denied
We cannot create ASM disks using the command: # /etc/init.d/oracleasm creatdisk ASMDISK1 /dev/mapper/mpathdp1 Marking disk "ASMDISK1" as an ASM disk: [FAILED] The log (/var/log/oracleasm) has the following: Clearing disk header: done Disk "ASMDISK1"