user1464296
user1464296

Reputation:

entity relationship between an actor and a receiver

So I have a SQL relationship problem. Lets say I have a database where I want to keep records of information about individuals. Now I have setup a table to take on that information. Okay so far so good.

Often times duplicate information can be discovered in the table and it would be removed. A record is considered a duplicate if a particular field has the same value as another field in another row. Example: Duplicate emails.

Now I want to create another table in the database to keep track of every duplicate that is ever discovered and deleted. My first thought into this was to create a Foreign Key relationship. So I created and then connected a dupes table to my persons table. The relationship was a simple Foreign to Primary key relationship with an on delete constraint.

Now while that may have worked at first the problem arose that the dupes table was receiving records that were deleted even if they were not deleted because they were dupes. This was a problem because even if I decided to delete a person from the persons table just because I did not like them, they would stored in the dupes table anyway.

Then I thought, why not create a disposition field in the persons table and connect that as a unique or primary key to my dupes table's index foreign key. Well the problem is a unique key must have a unique value so multiple dispositions of dupe or I don't like you would not work. The other option was to make the disposition field a primary key. That has the same problem though.

What would be the right relationship for this problem?

Upvotes: 0

Views: 123

Answers (2)

user1464296
user1464296

Reputation:

Foreign Keys are not going to solve this problem. I discovered Triggers and their exactly what I need.

Upvotes: 0

merlinbeard
merlinbeard

Reputation: 218

I can think of this implementation: An on delete trigger, with a 'before delete' check. The before delete check would confirm if the record being deleted is a duplicate or not. Not sure what all RDBMS systems support such checks though.

IMO, the theoritical relationship is complicated because the record is supposed to be preserved even after the dupe is deleted.

Upvotes: 1

Related Questions