我的意思是,如果我有以下模式:「跳過」在SQL內一個表連接
create table tableA(
A_id number not null primary key
);
create table tableB(
B_id number not null primary key,
A_id number not null references tableA(A_id),
B_data text not null
);
create table tableC(
C_id number not null primary key,
A_id number not null references tableA(A_id),
C_data text not null
);
如果我想找回B_data
和使用這裏所描述的關係C_data
,有什麼區別以下內容:
select
b.B_data,
c.C_data
from
tableB b
inner join tableC c
on b.A_id = c.A_id;
和:
select
b.B_data,
c.C_data
from
tableB b
inner join tableA a
on b.A_id = a.A_id
inner join tableC c
on a.A_id = c.A_id;
我SUS大多數數據庫將優化任何查詢都是相同的,但是有沒有這種情況下,tableA
的外鍵約束將使通過tableA
更有效地加入?有沒有這些查詢可能產生不同結果的情況?