시스템을 문서 관리 시스템으로 설명합니다. 그런 다음 한 가지 해결책은 시스템에서 엔티티의 문서화 된 성격의 우선 성을 존중하는 것입니다. 다음 모델은 문서 테이블에 대한 부모 역할을하는 추상 엔티티와 여러 하위 유형 테이블에 대한 수퍼 유형을 정의합니다. 이 모델을 사용하면 여러 문서를 DocumentedThing
과 연결할 수 있습니다.
DocumentedThing
---------------
ThingId Integer primary key
ThingType String check (ThingType in ('PUPIL', 'STAFF'))
unique key (ThingId, ThingType)
Document
--------
ThingId Integer foreign key references DocumentedThing (ThingId)
DocumentId Integer primary key
Text Clob
Pupil
-----
PupilId Integer primary key
ThingId Integer unique key
ThingType String check (ThingType = 'PUPIL')
Name String
DateOfBirth Date
foreign key (ThingId, ThingType)
references DocumentedThing (ThingId, ThingType)
Staff
-----
StaffId Integer primary key
ThingId Integer unique key
ThingType String check (ThingType = 'STAFF')
Name String
HireDate Date
foreign key (ThingId, ThingType)
references DocumentedThing (ThingId, ThingType)
고유 키의 발판은 DocumentedThing
가 Staff
또는 Pupil
하지만 두 곳의 기록을 가지고 수 있도록합니다. 또한 모든 하위 유형 테이블에는 여러 레코드가있을 수 없습니다. Staff
의 레코드는 에 'STAFF'값이있는 DocumentedThing
의 레코드에만 매핑 할 수 있습니다. 시행하기 어려운 한 가지는 DocumentedThing
은에 하위 유형 레코드가 있어야한다는 주장입니다. 이 작업은 수행 할 수 있지만 일반적으로 복잡하며 어느 정도까지는 DBMS 제품 선택에 따라 다릅니다.
새로운 하위 유형을 추가하면 영향을 최소화 할 수 있습니다. 정보를 보유 할 실제 테이블을 추가하는 것 외에 DocumentedThing.ThingType
에 새 값을 추가하기 만하면됩니다. 하위 유형이 많은 경우 점검 제한 조건이 아닌 룩업 테이블로 외래 키를 사용하여이를 제한 할 수 있습니다.
출처
2009-09-28 00:46:59
APC
중복 된 http://stackoverflow.com/questions/695752/product-table-many-kinds-of-product-each-product-has-many-parameters/ –