1

我一直在試圖弄清楚這在我的腦海中,但我真的卡住,並希望得到一些幫助。鑑於該計劃基於功能依賴關係的方案

R(a,b,c,d) 
fd1: a->c 
fd2: b->d 

準確地說,這裏的關鍵是{a,b}?如果這是真的,那麼也可以準確地說,由於它們對a或b的部分依賴性,屬性c,d需要在他們自己的表中?導致以下方式的計劃?

R(a,b) 
r1(a,c) 
r2(b,d) 

還是會被正確只是有

R(a,c) 
r1(b,d) 

當然A,B都存在於某種形式的,因爲他們是關鍵吧?我不是100%確定的。幫助理解這將會很好

回答

2

{a,b}是R的唯一鍵。R在1NF中。

爲了達到至少2NF,通過投影去除部分關鍵依賴關係。

  • ř {一個Ç}
  • ř {b d}

這是最小蓋。兩者都在6NF中。 R的關鍵不需要存在,因爲R不存在。但是R可以從r 和r 的笛卡爾積中恢復。

使用SQL。 。 。

create table t1 (
    a integer not null, 
    b integer not null, 
    c integer not null, 
    d integer not null, 
    primary key (a, b) 
); 

insert into t1 values 
(1, 1, 10, 100), 
(1, 2, 10, 200), 
(2, 1, 20, 100), 
(2, 2, 20, 200); 

請注意,這保留FD a-> c和b-> d。

create table t2 (
    a integer primary key, 
    c integer not null 
); 

insert into t2 
select distinct a, c from t1; 

create table t3 (
    b integer primary key, 
    d integer not null 
); 

insert into t3 
select distinct b, d from t1; 

drop table t1; 

現在我們可以看看錶格t2和t3中的數據。

select * from t2; 
a c 
-- 
1 10 
2 20 

select * from t3; 
b d 
-- 
1 100 
2 200 

而且我們可以通過t2和t3的笛卡爾乘積來恢復t1。

select t2.a, t3.b, t2.c, t3.d 
from t2, t3; 
a b c d 
-- 
1 1 10 100 
1 2 10 200 
2 1 20 100 
2 2 20 200