데이터베이스의 자식 테이블에서 반복되는 ID를 갖는 것이 장단점입니다.어린이 테이블의 반복 된 ID
예를 들어, 테이블 parent
고려 :
create table parent (
id int,
a text,
b text
)
을 그리고이 parent
그것을 참조하는 child1
테이블이 있습니다 : 미세하고 좋은, 그리고 아무것도 모든
create table child1 (
id int,
parent_id int not null references parent(id),
c text,
d text
)
유달리.
는create table child2 (
id int,
child1_id int not null references child1(id),
e text,
f text
)
create table child3 (
id int,
child2_id int not null references child2(id),
g text,
h text
)
I는 데 문제는 더 당신이 내려, 더 지루한는 위쪽으로 길을 가입됩니다 : 당신은 드릴 다운 지킬 문제는 온다. 내가 생각 한 하나 개의 솔루션은 모든 자식 테이블에 parent
ID를 반복하는 것입니다
create table child2 (
id int,
parent_id int not null references parent(id),
child1_id int not null references child1(id),
e text,
f text
)
create table child3 (
id int,
parent_id int not null references parent(id),
child2_id int not null references child2(id),
g text,
h text
)
이 조인의 수를 줄일 수 있습니다뿐만 아니라 데이터베이스 무결성에 영향을 미칩니다. child1
의 부모를 전환하면 항상 parent_id
열을 모두 업데이트해야합니다. 내 질문입니다 :이 상황을 처리하는 다른 방법이 있습니까? 그렇지 않으면 데이터 무결성을 유지하면서 하위 테이블에서 ID를 반복 할 수있는 방법이 있습니까?