0

3表架构:

create table EMP
(ID char(9) not null primary key,
NAME varchar(20) not null,
AGE integer not null,
SALARY number not null,
constraint min_salary check (salary>30000));

create table DEPARTMENT
(DNUMBER integer not null primary key,
 DNAME varchar(15) not null unique,
 BUDGET float not null,
 MANAGER char(9) not null references EMP);

create table WORKS
(EMP char(9) not null references EMP,
DEPT integer not null references DEPARTMENT,
PCT_TIME integer,
constraint check_pct check (PCT_TIME between 0 and 100), constraint WORKS_PK PRIMARY KEY (EMP,DEPT));

这是什么查询:

select name,age
from emp,department,works
where id=emp and dname='Software' and dept=dnumber

它从 3 个表中选择但没有连接关键字?

4

3 回答 3

3
select name,age
from emp,department,works
where id=emp and dname='Software' and dept=dnumber

...似乎是一个隐式内部连接查询。表,之间有效地做 a CROSS JOIN,返回笛卡尔积,而where id=emp and dname='Software' and dept=dnumber有效地过滤笛卡尔积,产生与 a 相同的效果INNER JOIN。标准字段没有用表名限定,因为它们没有歧义。

某些数据库引擎可能不会为这种类型的连接创建像显式内部连接查询那样有效的查询计划。

于 2013-09-18T00:57:25.653 回答
0

我相信这被称为笛卡尔积。它被定义为在没有限制因素的情况下链接表,例如连接语句。

刚刚从这里确认:http ://wiki.answers.com/Q/What_is_sql_cartesian_product

于 2013-09-18T00:51:27.453 回答
0

这是正确的。您可以选择:

SELECT * FROM Table1, Table2

这将做一个完整的右外连接

如果要进行左连接,请执行以下操作:

SELECT * FROM Table1, Table2 WHERE Table1.FID = Table2.ID

(其中 FID 是表 2 中 id 的外部 id)。

所以基本上,您的查询仍然是一个连接查询。

于 2013-09-18T00:52:32.137 回答