Reputation: 31
I have 2 questions regarding a project. Would appreciate if I get clarifications on that.
I have decomposed Address into individual entities by breaking down to the smallest
unit. Bur addresses are repeated in a few tables. Like Address fields are there in the
Client
table as well as Employee
table. Should we separate the Address into a separate table with just a linking field
For Example
Create an ADDRESS
Table with the following attributes :
Remove all the address fields from the Employee
table and the Client
table
We can obtain the address by getting the employee
ID and referring the ADDRESS
table for the address
Which approach is better ? Having the address fields in all tables or separate as shown above. Any thoughts on which design in better ?
Upvotes: 1
Views: 628
Reputation: 26518
Ya definitely separating address is better Because people can have multiple addresses so it will be increasing data redundancy.
You can design the database for this problem in two ways according to me.
A. Using one table
Table name --- ADDRESS
Column Names
B. Using Two tables
Table name --- CLIENT_ADDRESS
Column Names
Table name --- EMPLOYEE_ADDRESS
Column Names
Definitely you can use as many number of columns instead of address like what you mentioned Unit,Building, Street e.t.c
Also there is one suggestion from my experience
Please add this five Columns in your each and every table.
The reason for this from point of view of most of the developers is, Your client can any time demand records of any time period. So If you are deleting in reality then it will be a serious situation for you. So every time when a application user deleted an record from gui you have to set the flag as 0 instead of practically deleting it. The default value is 1 which means the row is still active.
At time of retrieval you can select with where condition like this
select * from EMPOLOYEE_TABLE where DELETE_FLAG = 1;
Note : This is an suggestion from my experience. I am not at all enforcing you to adopt this. So please add it according to your requirement.
ALSO tables which don't have any significant purpose doesn't need this.
Upvotes: 3
Reputation: 15023
Separating address into a seperate table is a better design decision as it means any db-side validation logic etc. only needs to be maintained in one place.
Upvotes: 1