I have this person table as super parent,
id
firstname
lastname
email
telephone
...
...
and user table as a child
id
person_id (FK)
password
username
screenname
...
...
They must be 1:1 relationship, because an user cannot be repeated twice. and so the email in the person row must not be repeated twice.
Then I have this message table which stores messages from anyone,
id
firstname
lastname
email
telephone
subject
content
...
...
but you can see that firstname,lastname, email,telephone are duplicated in message table.
so I am thinking to refer it to person table like this below,
id
person_id
subject
content
...
but then it does not seem right, as a person with the same email, name, etc can send message to me as many times as they want. so the details he/she provides can be repeated.
so should I make message as a child of person the parent or they should be separate entities?
or any better suggestions to solve this problem.
You have to decide what you want your system to do. Do you want old messages to reflect someone’s new name or do you want each message to have the name (and other details) which were in effect when the message was created?
If you want the system to only reflect the current personal details then all your message needs is a foreign key to PERSON.
If, on the other hand, you want your messages to look the same way for all time, even if the person who sent them changes their name, email address or other details, then you have to find a way to keep the historical information. Two obvious choices would be (i) denormalize the person details down to the message – as in your current design or (ii) keep a history table of PERSON with snapshots of each combination of personal details with MESSAGE referring to the appropriate person history record with a foreign key.