Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to control the duplicate primary key!!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello, I would like to do a trigger to control the duplicate primary key,How to do it?
thanks a lot,
Regards,
 
if
(select count(*) from xxx where col1Key=x,col2Key=y...)>0 begin
do something
end John Fill
 
Serji,

Are you trying to implement a trigger to stop duplicate rows from being inserted ? or to handle the error caused an existing constraint ?

If the former, then the (Oracle 8i) syntax for adding a primary key contraint is shown below, if the latter, you may be better putting a trap similar to JohnFill's in the code before your insert, or giving your insert statement an exception handler. Triggers can be a bit funny when it comes to doing selects from the affected table.

[tt]
ALTER TABLE Subject_Transforms
ADD (CONSTRAINT XPKSubject_Transforms
PRIMARY KEY (dimension_name, subject_id))
/[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top