GATE CSE
First time here? Checkout the FAQ!
x
+2 votes
48 views

asked in Databases by Loyal (3.5k points)   | 48 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 (76.9k points)  
edited ago 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

Related questions

0 votes
0 answers
1
asked ago in Databases by srestha Veteran (58.4k points)   | 27 views
+2 votes
1 answer
2


Top Users Sep 2017
  1. Habibkhan

    6960 Points

  2. Warrior

    2424 Points

  3. Arjun

    2358 Points

  4. rishu_darkshadow

    2136 Points

  5. A_i_$_h

    2004 Points

  6. nikunj

    1980 Points

  7. manu00x

    1750 Points

  8. makhdoom ghaya

    1750 Points

  9. Bikram

    1744 Points

  10. SiddharthMahapatra

    1718 Points


26,059 questions
33,665 answers
79,739 comments
31,078 users