So it “double lookup” is frequently used whenever yourself interrogating a dining table one to represents good recursive relationship
For people who check emp , you will see that this new manager of the worker with empno = 2 (Ned) enjoys bossno = step one. You’ll be able to lookup new row inside the emp which have empno = 1 to get one to Ned’s employer was Alice. In the near future you’ll discover exactly how this is treated that have SQL.
You will see that there’s no overseas secret meaning to possess empno inside the dept (the fresh step one:1 department’s employer relationship). As to the reasons? Observe that deptname are a different key in emp . Whenever we build empno a different type in dept , up coming we have a life-threatening accept. A new company cannot be put in the fresh new dept dining table until there is certainly a boss for the company (we.age., there was a person in the fresh new emp table toward empno of the manager); however, additional constraint says you to definitely a worker can not be put into this new emp desk except if there clearly was a department that one body is assigned. When we has actually both foreign key constraints, we can not include a different company up to i have added a manager, and we dont incorporate a supervisor up to i’ve added a good company regarding individual. Absolutely nothing, around these situations, can happen if the each other overseas trick restrictions are located in place. For this reason, only 1 of them are given.
Regarding the new recursive staff member dating, we are able to do a constraint in order for bossno is present getting for every staff, except however anyone, Alice, that is top of the pyramid. Continua a leggere