Auto Relationship

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
  

Poston Wed, 29 Nov 2006 4:45 pm

Srs. Does anyone have any examples of Auto Relationship.

Thank you once again!
jctq
Location: São Gonçalo

Att,
Julio Quintão

Poston Thu, 07 Dec 2006 10:42 am

A auto-relacionamento is a relationship made with the table itself.
An example of this is when you want to combine things:
Code: Select all
EMPREGADO NOME        CHEFE
--------- ----------- -----
10        JOAO        40
20        PEDRO       40
30        CARLOS      40
40        THE BOSS
see table above. All employees have a boss (40) which is one of the people registered. The 40 has no head, then the auto-relacionamento field is blank.


To create, can do so (using the table above):
Code: Select all
alter table EMPREGADOS
  add constraint EMPR_EMPR_FK foreign key (CHEFE)
  references EMPREGADOS (EMPREGADO);
to query the auto-relacionamentos that exist, we can do it like this:
Code: Select all
select a.table_name
from user_constraints a
where exists (select 1
              from user_constraints b
              where a.constraint_name=b.r_constraint_name
                and a.table_name     =b.table_name)
dr_gori
Location: Portland, OR USA

Thomas F. G

Você já respondeu a dúvida de alguém hoje?
http://glufke.net/oracle/search.php?search_id=unanswered

Poston Tue, 26 Jun 2007 11:10 am

Despite this topic be a little old, wanted to take him to clarify a doubt which arose here at work.

In the sample table EMPLOYEES, as would the Select query to be listed all employees with code, name, code and name of the boss's boss?
xandesantos
Location: Salvador-BA



Return to SQL

Who is online

Users browsing this forum: No registered users and 2 guests