0

I am designing one to one relationship with EMPLOYEE and ACCOUNT table

this is account table

Account
<<pk>> account_id
account_number

and here is Employee table

Employee
<<pk>> employee_id
employee_name
designation
salary
hire_date

so here my question is should employee table contain fk for account_id or account table contain fk for employee_id? and How to decide which side should contain fk?

eatSleepCode
  • 4,427
  • 7
  • 44
  • 93
  • if an account has one and only one employee related, then just add employee id as foreign key in your accounts table... if not, then create a new "relationship" table... – Julo0sS Aug 31 '15 at 07:14
  • yes there is one to one relationship between employee and account – eatSleepCode Aug 31 '15 at 07:18

2 Answers2

0

For your approach if the account id is unique for each employee then it doesn't matter whether the account table have the employ id or the employee table have the account id. But if an account will hare between multiple employee then the account id should be present in employee table eg. some project expenditure account etc.

smn_onrocks
  • 1,282
  • 1
  • 18
  • 33
0

There is no fix rule how you have to do it. As Jul0sS wrote it depends on you how YOU see the dependencies. If an Employee has exactly one account then the Employee should know the account hence has the fk for the account_id.

You may be interested in this discussion about WHY use 1 to 1 relationship.

Community
  • 1
  • 1
SWiggels
  • 2,159
  • 1
  • 21
  • 35