0

SQL Server를 데이터베이스로 사용하는 웹 응용 프로그램이 있다고 가정 해 봅니다.동일한 기본 키에 따라 복수의 외래 키

I가 Sections

IDdepartment, IDstore, codTax, accountSell, accountTax, status, m1, m2 

-> PK (IDdepartment, IDstore, codTax) 
FK (accountSell, accountTax) on AccountPlan (accounCompany) 
AccountPlan

AccountCod, account, description, account_desc, accountCompany, type, mov) 

-> PK (accountCompany) 

accountSell

accountTaxaccountCompany 다른 테이블에서 동일한 값을 포함하는 2 외래 키가 하나 개의 테이블

표 의존 한 . 둘 다 accountCompany에서 사용할 수있는 모든 값을 포함 할 수 있습니다.

쿼리를 수행 할 때이 내용을 알고 싶습니다.이를 수행하는 방법은 accountCompany입니까?

실제로 중복 된 데이터가있는 두 개의 테이블을 사용하고 있습니다. 동일한 테이블을 하나만 사용하는 것이 가능하다고 생각합니다. 희망이 가능할 수 있습니다.

감사합니다 ...

답변

0

는 솔직히 당신이 정말로 중복 된 데이터를 두 개의 테이블이없는 희망 않습니다.

create table Section 
(
    accountSell int not null foreign key references AccountPlan(accountCompany), 
    accountTax int not null foreign key references AccountPlan(accountCompany) 
) 

당신은 두 번 같은 테이블에 가입하여 설명을 얻을 수 있습니다 : 동일한 테이블을 가리키는 두 개의 FKS 데 아무 문제가 없습니다에 대한

select 
    sell.description as accountSell_description, 
    tax.description as accountTax_description 
from 
    Section s 
    inner join AccountPlan sell on sell.accountCompany = s.accountSell 
    inner join AccountPlan tax on tax.accountCompany = s.accountTax 
+0

모든 전에 ... 감사는 도움이 ... 매우 중요했습니다, 나는 DB 정규화의 모든 이론적 인 단계를 만들어야했습니다 ... 처음에는 시간이 부족했기 때문에 '망치질'을해야하고, 지금은 이런 종류의 문제가 나타나고 있습니다! ! 그게 인생의 교훈이야. – user3414753