sql多表查询练习题

  1. 在SQL中,如果需要删除表t01和t02并自动删除它们的依赖对象,应该使用哪个命令?

A. DROP TABLE t01, t02;

B. DROP TABLE IF EXISTS t01, t02;

C. DROP TABLE IF EXISTS t01 CASCADE; DROP TABLE IF EXISTS t02 CASCADE;

D. DROP TABLE t01 CASCADE; DROP TABLE t02 CASCADE;

答案:C

  1. 创建表t01和t02的正确SQL语句是什么?

A. CREATE TABLE t01(id1 int, id2 int, id3 int); CREATE TABLE t02(id1 int, id4 int, id5 int);

B. CREATE TABLE t01(id1 int,id2 int,id3 int): CREATE TABLE t02(id1 int,id4 int,id5 int);

C. CREATE TABLE t01(id1 int, id2 int, id3 int), t02(id1 int, id4 int, id5 int);

D. CREATE TABLE t01 {id1 int, id2 int, id3 int} CREATE TABLE t02 {id1 int, id4 int, id5 int}

答案:A

  1. 插入数据到t01和t02表的正确SQL命令是什么?

A. INSERT INTO t01 VALUES(1,1,1),(2,2,2),(3,3,3);

INSERT INTO t02 VALUES(1,4,4),(2,2,2),(4,6,6);

B. INSERT INTO t01 (1,1,1),(2,2,2),(3,3,3);

INSERT INTO t02 (1,4,4),(2,2,2),(4,6,6);

C. INSERT INTO t01 VALUES{1,1,1}, {2,2,2}, {3,3,3} ;

INSERT INTO t02 VALUES{1,4,4}, {2,2,2}, {4,6,6};

D. INSERT INTO t01 (VALUES(1,1,1),(2,2,2),(3,3,3)) ;

INSERT INTO t02 (VALUES(1,4,4),(2,2,2),(4,6,6));

答案:A

  1. 使用INNER JOIN子句查询t01和t02所有字段的正确SQL命令是什么?

A. SELECT * FROM t01 INNER JOIN t02 ON t01.id1=t02.id1

B. SELECT * FROM t01 JOIN t02 WHERE t01.id1=t02.id1

C. SELECT * FROM t01 INNER JOIN t02 WHERE t01.id1=t02.id1

D. SELECT * FROM t01, t02 WHERE t01.id1=t02.id1

答案:A

  1. 在SQL中,如何通过为表设置别名简化SQL语句?

A. SELECT * FROM t01 a INNER JOIN t02 b ON a.id1=b.id1

B. SELECT * FROM t01 AS a INNER JOIN t02 AS b ON a.id1=b.id1

C. SELECT * FROM t01 a JOIN t02 b WHERE a.id1=b.id1

D. SELECT * FROM t01 a, t02 b WHERE a.id1=b.id1

答案:A

  1. 以下哪个SQL命令表示等价于SELECT * FROM t01 a LEFT JOIN t02 b ON a.id1=b.id1;?

A. SELECT * FROM t01 a, t02 b WHERE a.id1=b.id1(+)

B. SELECT * FROM t01 a, t02 b WHERE a.id1=b.id1

C. SELECT * FROM t01 a RIGHT JOIN t02 b ON a.id1=b.id1

D. SELECT * FROM t01 a INNER JOIN t02 b ON a.id1=b.id1

答案:A

  1. 使用WHERE子句代替INNER JOIN ON关键字的正确SQL命令是什么?

A. SELECT * FROM t01 a, t02 b WHERE a.id1=b.id1

B. SELECT * FROM t01 a INNER JOIN t02 b WHERE a.id1=b.id1

C. SELECT * FROM t01 a JOIN t02 b ON a.id1=b.id1

D. SELECT * FROM t01 a, t02 b ON a.id1=b.id1

答案:A

  1. 左外连接(LEFT OUTER JOIN)的正确SQL命令是什么?

A. SELECT * FROM t01 a LEFT JOIN t02 b ON a.id1=b.id1

B. SELECT * FROM t01 a LEFT OUTER JOIN t02 b WHERE a.id1=b.id1

C. SELECT * FROM t01 a INNER JOIN t02 b ON a.id1=b.id1

D. SELECT * FROM t01 a, t02 b WHERE a.id1=b.id1

答案:A

  1. 全外连接(FULL OUTER JOIN)的正确SQL命令是什么?

A. SELECT * FROM t01 a FULL OUTER JOIN t02 b ON a.id1=b.id1

B. SELECT * FROM t01 a JOIN t02 b ON a.id1=b.id1

C. SELECT * FROM t01 a FULL JOIN t02 b ON a.id1=b.id1

D. SELECT * FROM t01 a, t02 b WHERE a.id1=b.id1

答案:A

  1. 交叉连接(CROSS JOIN)也称为什么?

A. 笛卡尔积

B. 内连接

C. 外连接

D. 自然连接

答案:A

  1. 在SQL中,非等值连接可以是哪种类型的连接?

A. 仅内连接

B. 仅外连接

C. 内连接或外连接

D. 自然连接

答案:C

  1. 以下哪个SQL命令表示全外连接?

A. SELECT * FROM t01 a LEFT JOIN t02 b ON a.id1=b.id1

B. SELECT * FROM t01 a RIGHT JOIN t02 b ON a.id1=b.id1

C. SELECT * FROM t01 a FULL OUTER JOIN t02 b ON a.id1=b.id1

D. SELECT * FROM t01 a INNER JOIN t02 b ON a.id1=b.id1

答案:C

  1. 自然连接可以是哪种类型的连接?

A. 仅内连接

B. 仅外连接

C. 内连接或外连接

D. 交叉连接

答案:C

  1. 使用USING关键字代替连接条件的SQL命令是什么?

A. SELECT * FROM t01 a INNER JOIN t02 b ON a.id1=b.id1

B. SELECT * FROM t01 a JOIN t02 b USING(id1)

C. SELECT * FROM t01 a, t02 b WHERE a.id1=b.id1

D. SELECT * FROM t01 a FULL OUTER JOIN t02 b ON a.id1=b.id1

答案:B

  1. 以下哪个SQL命令会生成笛卡尔积?

A. SELECT * FROM t01 a INNER JOIN t02 b ON a.id1=b.id1

B. SELECT * FROM t01 a CROSS JOIN t02 b

C. SELECT * FROM t01 a, t02 b WHERE a.id1=b.id1

D. SELECT * FROM t01 a INNER JOIN t02 b

答案:BD

  1. 当连接过程中提供了无效的连接条件,结果会变成什么?

A. 空集

B. 笛卡尔积

C. 内连接

D. 外连接

答案:B

  1. 以下哪个SQL命令表示左外连接?

A. SELECT * FROM t01 a LEFT JOIN t02 b ON a.id1=b.id1

B. SELECT * FROM t01 a RIGHT JOIN t02 b ON a.id1=b.id1

C. SELECT * FROM t01 a FULL OUTER JOIN t02 b ON a.id1=b.id1

D. SELECT * FROM t01 a INNER JOIN t02 b ON a.id1=b.id1

答案:A

  1. 以下哪个SQL命令表示右外连接?

A. SELECT * FROM t01 a RIGHT JOIN t02 b ON a.id1=b.id1

B. SELECT * FROM t01 a LEFT JOIN t02 b ON a.id1=b.id1

C. SELECT * FROM t01 a FULL OUTER JOIN t02 b ON a.id1=b.id1

D. SELECT * FROM t01 a INNER JOIN t02 b ON a.id1=b.id1

答案:A

相关推荐
天天扭码8 分钟前
五天SpringCloud计划——DAY2之单体架构和微服务架构的选择和转换原则
java·spring cloud·微服务·架构
程序猿进阶9 分钟前
堆外内存泄露排查经历
java·jvm·后端·面试·性能优化·oom·内存泄露
FIN技术铺13 分钟前
Spring Boot框架Starter组件整理
java·spring boot·后端
小曲程序20 分钟前
vue3 封装request请求
java·前端·typescript·vue
gma99929 分钟前
Etcd 框架
数据库·etcd
爱吃青椒不爱吃西红柿‍️32 分钟前
华为ASP与CSP是什么?
服务器·前端·数据库
陈王卜38 分钟前
django+boostrap实现发布博客权限控制
java·前端·django
小码的头发丝、38 分钟前
Spring Boot 注解
java·spring boot
java亮小白199743 分钟前
Spring循环依赖如何解决的?
java·后端·spring
飞滕人生TYF1 小时前
java Queue 详解
java·队列