Home » SQL & PL/SQL » SQL & PL/SQL » Unique Constraint
Unique Constraint [message #19226] Wed, 06 March 2002 03:16 Go to next message
Aditya Banerjee
Messages: 1
Registered: March 2002
Junior Member
I have a table t1 with columns id (PK) and name.
data is
ID NAME
1 adi
second table I have is t2 with columns id and name.
data is
ID NAME
2 xyz
3 abc
1 adi
If I say
INSERT INTO T1 SELECT * FROM T2.
It fails with Unique Constraint Violation (which is likely).

Now if I want that when I execute this query which is failing with unique constraint, the erroneous record causing the failure.
To be more clear, Can oracle return me the error as well as the erroneous record causing the problem. Or I need to write one more sql for finding it myself.

Aditya
Re: Unique Constraint [message #19227 is a reply to message #19226] Wed, 06 March 2002 04:18 Go to previous message
pratap kumar tripathy
Messages: 660
Registered: January 2002
Senior Member
1.why do not u try this way

INSERT INTO T1
SELECT * FROM T2
where id not in (select id from T1)
2."INSERT INTO T1 SELECT * FROM T2" is a statement which is trying to insert one/more record into table T1. This statement will fail if one or more of the record does not statisfy the constraint(s).oracle can not say which record caused the problem.
3. the workaround is to select record from T2 adn try to insert one by one to T1, in that case oracle will say which row is causing problem

hope this helps!!!
Previous Topic: Trigger problem!!!
Next Topic: ORA-00903
Goto Forum:
  


Current Time: Sat Apr 20 02:58:11 CDT 2024