The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+2 votes
68 views

asked in Databases by Boss (6.7k points) | 68 views

If eid is Primary key in both Emp and did is the primary key in Dept. 

then we can say that eid from Emp is referring eid in Works. that makes it a Foreign Key.

and did from Works is referring did from Dept and that makes it a foreign key.

hence we have 2 foreign keys.

1 Answer

+2 votes
Best answer

Assuming many to many relation i.e. 

An employee can work in multiple departments and a department has more than one employees

In that case each of the three tables(relations) mentioned will remain separate ; i.e. neither of them can be merged to other..In that case  eid of "works" relation (which is a table of relationship between emp and dept entities) which is referencing to "employee" relation and did which references to "dept" relation.. 

Considering the case that a manager is also an employee so manager_id should be a valid eid..Hence manager_id should reference to eid..Hence manager_id can also be a foreign key under this scenario..

Hence number of foreign keys possible   =   3  for the mentioned scenario..

answered by Veteran (96.7k points)
selected by
but we can also take manager id as foreign key

 srestha i think manager id also will be foreign key

how manager id could be foreign key?see foreign key definition. Which are two tables manager id  contains?
emloyee can be manager,by this assumption we can refer manager id to emloyee id

becoz question is asked about possible foreign key
Manager_id is foreign key in the scenario that the table "dept" is self referential relation..

But here we have assumed "dept" to be an entity..
Like eid of "works" refers to eid of "Emp"

similarly can manager_id not refers to eid in "Emp"

as one of the employee going to be the manager of the department.

please clear

srestha  Habibkhan

why we are not taking manager id as a foreign key ,it may be refer to emp table 

@set2018

eid is primary key for Emp table

dept table contain did as primary key

What is the primary key for Works?

it must be (did,eid)

then mgrid will be the only foreign key of the total relation

rt?

@Habib chk once


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

29,157 questions
36,984 answers
92,161 comments
34,824 users