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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to avoid '' Key Violation ' error ?

Status
Not open for further replies.

benkiliane

Programmer
Mar 14, 2002
2
CA
My Table is created and it has primary key composed by three fields. I want to save record in the primary key Fields even it's already exists.
For the primary key I put UNIQUE = false but I have always key violation.
Can you Help me please as soon as possible.
Thank you
 
You can't. That's the point of Primary Keys; they must be unique. Presumably you want to restrict the PK to only 2 of those 3 fields.
 
When you create your table make one of them a N field, make it an Auto-increment field and Index on that. That way every time you create a new record it is unique and you cannot get a key-violation.

Hope it helps.
 
Put indexes on the foreign key fields, and don't make them Primary keys.

You say you want to save a record even if it already exists, if the records are exactly the same why are you saving it and if not what is the difference with the 'same' records ?

lou
[penguin]
 
Sorry, ignore my question about the records being exactly the same (can't read properly when early in morning), you mean when the key fields are the same.
 
I would be cautious on using autoincrement fields. Borland itself doesn't use them. If you look at the MastApp demo you will see a nice work around for creating unique key field numbers S. van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top