validation of primary key compound of several fields [message #153579] |
Tue, 03 January 2006 04:14 |
sbensimo
Messages: 6 Registered: December 2005
|
Junior Member |
|
|
Hi All,
I have a table which its primary key compound with fields A, B and C. the table has more fields D and F. (example field names)
now when saving a new record the primary key is checked that there is no duplicate combination of A, B and C in the database.
The problem is when changing an existing record:
If the change was in one of A,B,C then the select should look for one record with the same combination.
When the change was in one of D,F then we have already the key combination of A,B,C in the DB (of the current record) and the check will fine it and will not let to change fields D or F.
One way is to check the primary key whenever one of A,B,C fields is changed and in PRE-INSERT also.
but if the the primary key combination is 5 fields... is it a appropriate way to do it?
Is there any other way to make this check?
|
|
|
validation of primary key compound of several fields [message #153587 is a reply to message #153579] |
Tue, 03 January 2006 04:37 |
sbensimo
Messages: 6 Registered: December 2005
|
Junior Member |
|
|
Hi All,
I have a table which its primary key compound with fields A, B and C. the table has more fields D and F. (example field names)
now when saving a new record the primary key is checked that there is no duplicate combination of A, B and C in the database.
The problem is when changing an existing record:
If the change was in one of A,B,C then the select should look for one record with the same combination.
When the change was in one of D,F then we have already the key combination of A,B,C in the DB (of the current record) and the check will fine it and will not let to change fields D or F.
One way is to check the primary key whenever one of A,B,C fields is changed and in PRE-INSERT also.
but if the the primary key combination is 5 fields... is it a appropriate way to do it?
Is there any other way to make this check?
|
|
|
Re: validation of primary key compound of several fields [message #153722 is a reply to message #153587] |
Tue, 03 January 2006 20:56 |
|
djmartin
Messages: 10181 Registered: March 2005 Location: Surges Bay TAS Australia
|
Senior Member Account Moderator |
|
|
You do not handle an update via the pre-insert trigger, you use the pre-update trigger.
I don't like updating primary keys. Insert the new one and delete the old one. It is better to have a key that you will not be updating. If necessary use a sequence number.
David
|
|
|