Need help on primary key [message #226759] |
Mon, 26 March 2007 08:22 |
kanis
Messages: 61 Registered: November 2006
|
Member |
|
|
Need help on the below topic:
in one table has lots of data ,and have primary key on 5 columns.
Now in a procedure we need to insert values into the table.
In which way should we go ,when we insert same value(primary key) into the table....
1> Check the existance of the primary record by --select query.if dulpicate ,don't go .
2> Wait till primary key violation and trap it .
which will be the right way to implement in code .
pls suggest.
|
|
|
|
Re: Need help on primary key [message #226778 is a reply to message #226768] |
Mon, 26 March 2007 09:06 |
kanis
Messages: 61 Registered: November 2006
|
Member |
|
|
No this is not my question .
My question is that which way we should go ..
1> check before PK violation ,and do not insert record.
2> Go for PK violation and trap it
|
|
|
Re: Need help on primary key [message #226780 is a reply to message #226759] |
Mon, 26 March 2007 09:07 |
Bill B
Messages: 1971 Registered: December 2004
|
Senior Member |
|
|
Use an exception block, do NOT check for existance first.
....
...
begin
insert into my_table(col1,col2,col3...) values(....);
exception
when DUP_VAL_ON_INDEX THEN
..... HANDLE YOUR ERROR HERE;
END;
|
|
|
|
Re: Need help on primary key [message #226831 is a reply to message #226781] |
Mon, 26 March 2007 13:33 |
orausern
Messages: 826 Registered: December 2005
|
Senior Member |
|
|
I am not too sure, but here is what I wish I know:
1)post ur table structure.
2)the code that u use to insert data..for which you have the question related to pk.
3) in that code -point 2- how did u arrive at the value of PK?did u hard code it? or assume it? or did u use some mechanism to calculate it?
just my 1 cent...
|
|
|
Re: Need help on primary key [message #226853 is a reply to message #226831] |
Mon, 26 March 2007 15:07 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
nirav_hyd wrote on Mon, 26 March 2007 14:33 | I am not too sure, but here is what I wish I know:
1)post ur table structure.
2)the code that u use to insert data..for which you have the question related to pk.
3) in that code -point 2- how did u arrive at the value of PK?did u hard code it? or assume it? or did u use some mechanism to calculate it?
just my 1 cent...
|
Please use whole words.
|
|
|