2014-07-10 3 views
0

근무중인 회사와 다른 조직간에 체결 한 계약을 관리하는 응용 프로그램을 만드는 것이 좋습니다. 이를 위해 두 사람이 같은 조직에 속해 있는지 확인하십시오.

, 나는 다음과 같은 EER 다이어그램 생성 : 대회는 (테이블 협약에 organization_signatory)에 서명 한 사람과 담당자 모두를 포함해야 http://i.stack.imgur.com/kbLIi.png

가 유효하려면을 (organization_contact 테이블 협약) .

내 질문은 : 두 사람이 같은 회사에 속하는지 어떻게 확인합니까?

답변

0

제한을 추가해야합니다. 협약 organization_contact 값은 조직 가치가있는 Organization_staff ID로 나타납니다. 컨벤션 organization_signatory 값은 Organization_staff ID로 일부 Organization 값으로 나타납니다. 이 두 조직의 값을 같게하려고합니다.

-- Convention(id,...) 
fk (organization_contact) references Organization_staff (id) 
fk (organization_signatory) references Organization_staff (id) 
-- standard SQL but seldom supported 
check (
    (select id from Convention c JOIN Organization_staff s 
    where c.id = s.organization_contact) 
= (select id from Convention c JOIN Organization_staff s 
    where c.id = s.organization_signatory)) 

사용중인 도구가 무엇인지 알려주지 않으므로 이러한 도구를 표현하는 방법을 알 수 없습니다. 모델링 제품 & SQL DBMS는 임의의 ASSERTION 또는 CHECK 제약 조건을 잘 지원하지 않습니다. SQL 기술은 Applied Mathematics for Database Professionals을 참조하십시오. ASSERTION 및 CHECK 제약 조건 대신 stackoverflow를 검색 할 수 있습니다.

그러나 협약이 특정 조직과 관련되어있는 것은 합당한 것처럼 보입니다. 그 조직의 연락처와 서명자입니다.

fk (organization) references Organization (id) 
fk (organization_contact,organization) references Organization_staff (id, organization) 
fk (organization_signatory,organization) references Organization_staff (id, organization) 

SQL은으로 Organization_staff에 (중복 논리적)에 FK 목표를 선언 할 필요

unique (id, organization) 

그러나 당신은 단순히 쉽게 연락처 및 서명 조직 제약 조건을 만들기위한 목적으로 협약에 조직을 선언 할 수 있습니다 이렇게 선언적으로 표현할 수 있습니다. 그러한 목적을 위해 SQL에서 그러한 관용구를 사용합니다.

+0

답장을 보내 주셔서 감사합니다. –

관련 문제