作业参考答案

Similar documents
ebook 165-5

untitled

PowerPoint Presentation

untitled

目錄 C ontents Chapter MTA Chapter Chapter

单元四数据的查询 数据库原理与应用 课内例题 任务 5 多表查询 课内例题 例创建数据表 orders, 并向表中添加记录 首先创建表 orders,sql 语句如下 : CREATE TABLE orders( o_num int NOT NULL AUTO_INCREMENT, o_date d

PowerPoint Presentation

一步一步教你搞网站同步镜像!|动易Cms

目錄

DB2 (join) SQL DB2 11 SQL DB2 SQL 9.1 DB2 DB2 ( ) SQL ( ) DB2 SQL DB2 DB2 SQL DB2 DB2 SQL DB2 ( DB2 ) DB2 DB2 DB2 SQL DB2 (1) SQL (2) S

习题1

學 科 100% ( 為 單 複 選 題, 每 題 2.5 分, 共 100 分 ) 1. 請 參 閱 附 圖 作 答 : (A) 選 項 A (B) 選 項 B (C) 選 項 C (D) 選 項 D Ans:D 2. 下 列 對 於 資 料 庫 正 規 化 (Normalization) 的 敘

SQL Server SQL Server SQL Mail Windows NT

ebook4-14

目錄... ivv...vii Chapter DETECT

Microsoft PowerPoint - Ch6

Microsoft Word - 1-3陳詠琳-近代..

数 据 库 系 统 基 础 2/54 第 6 章 数 据 库 管 理 与 维 护

untitled

第 一 节 认 识 自 我 的 意 义 一 个 人 只 有 认 识 自 我, 才 能 够 正 确 地 认 识 到 自 己 的 优 劣 势, 找 出 自 己 的 职 业 亮 点, 为 自 己 的 顺 利 求 职 推 波 助 澜 ; 一 个 人 只 有 认 识 自 我, 才 能 在 求 职 中 保 持

untitled

ebook46-23

季刊9web.indd

未命名

RUN_PC連載_12_.doc

6-1 Table Column Data Type Row Record 1. DBMS 2. DBMS MySQL Microsoft Access SQL Server Oracle 3. ODBC SQL 1. Structured Query Language 2. IBM

R D B M S O R D B M S R D B M S / O R D B M S R D B M S O R D B M S 4 O R D B M S R D B M 3. ORACLE Server O R A C L E U N I X Windows NT w w

Microsoft Word 年9月二级VF真卷.doc

目 錄 1. 青 椒 炒 肉 絲 2 2. 茄 汁 燴 魚 片 3 3. 乾 煸 四 季 豆 4 4. 黑 胡 椒 豬 柳 5 5. 香 酥 花 枝 絲 6 6. 薑 絲 魚 片 湯 7 7. 醋 瓦 片 魚 8 8. 燜 燒 辣 味 茄 條 9 9. 炒 三 色 肉 丁 榨 菜 炒

2

untitled

123

1. 概 述 1.1 扫 描 对 象 序 号 1 IP 地 址 域 名 1.2 漏 洞 等 级 分 布 风 险 类 型 数 量 高 风 险 1 中 风 险 5 低 风 险 4 信 息 类 4 7% 29% 高 风 险 36% 中 风 险 低 风

untitled

Oracle高级复制冲突解决机制的研究

Oracle 4

教 学 目 标 描 述 主 要 数 据 库 对 象 创 建 表 描 述 列 定 义 时 可 用 的 数 据 类 型 改 变 表 的 定 义 删 除 改 名 和 截 断 表 描 述 每 个 DML 语 句 插 入 行 到 表 中 更 新 表 中 的 行 从 表 中 删 除 行 描 述 约 束 创 建

ASP.NET实现下拉框二级联动组件

1-1 database columnrow record field 不 DBMS Access Paradox SQL Server Linux MySQL Oracle IBM Informix IBM DB2 Sybase 1-2

2006年暑期工作安排

第二章 关系数据库

幻灯片 1

Microsoft Word - TR-REC-05科学数据库建库技术指导规范

精 品 库 我 们 的 都 是 精 品 _www.jingpinwenku.com (8) 数 据 库 数 据 库 系 统 和 数 据 库 管 理 系 统 之 问 的 关 系 是 ( ) A) 数 据 库 包 括 数 据 库 系 统 和 数 据 库 管 理 系 统 B) 数 据 库 系 统 包 括

一 個 SQL Injection 實 例 的 啟 示 頁 2 / 6 因 此, 在 知 名 網 站 上 看 到 SQL Injection, 讓 人 驚 心, 卻 不 意 外 網 站 專 案 外 包 是 目 前 業 界 的 常 態, 而 在 價 格 取 勝 的 制 度 下, 低 價 得 標 的 S

深入理解otter

第1套

幻灯片 1

ZENworks 11 SP4

SP_ SP_03 JAVA...6 SP_10 SQL...8 SP_ SP_ SP_ SP_ SP_ SP_ SP_ SP_04.NET...33 SP_02 C...37 SP_05

MySQL資料庫教學

致理技術學院資訊管理學系專題企劃書格式建議書

回滚段探究

学 习 方 法 从 系 统 设 计 的 角 度 而 非 程 序 设 计 的 角 度 去 学 数 据 库 系 统 数 据 库 管 理 系 统 数 据 库 应 用 系 统 问 题 驱 动 科 学 问 题 技 术 问 题 应 用 ( 工 程 ) 问 题 认 真 做 作 业 亲 自 动 手 设 计 和 实

SDK 概要 使用 Maven 的用户可以从 Maven 库中搜索 "odps-sdk" 获取不同版本的 Java SDK: 包名 odps-sdk-core odps-sdk-commons odps-sdk-udf odps-sdk-mapred odps-sdk-graph 描述 ODPS 基

幻灯片 1

幻灯片 1

数据库系统概论

Microsoft PowerPoint - 05-SQL3-advanced.ppt

SQL: Interactive Queries (2)

ebook45-5

untitled

高中信息技术课程标准

目 录 1.1. 范 围 数 据 类 型 数 据 集 列 表 公 共 卫 生 数 据 集... 4 健 康 档 案 管 理... 4 健 康 教 育 管 理 预 防 接 种 儿 童 保 健 老 年 人 健


【例2

ebook 96-16

Microsoft Word - 数据库实验2007.doc

四川省普通高等学校

数据库系统概论

课程名称:数据库系统概论

基于UML建模的管理管理信息系统项目案例导航——VB篇

电 气 工 程 师 : 李 志 给 排 水 工 程 师 : 彭 永 芳 暖 通 工 程 师 : 金 红 波 给 排 水 工 程 师 : 胡 江 平 结 构 工 程 师 : 顾 太 华 电 气 工 程 师 : 郭 锋 单 位 名 称 : 深 圳 金 粤 幕 墙 装 饰 工 程 有 限 公 司 单 位

Microsoft Word - sql_1__周燕红_ doc


5. 下列条件子句中, 能够筛选出价格不在 ( 不包括边界值 ) 的是 ( ) A. Where 价格 NOT BETWEEN 100 AND 200 B. Where 价格 BETWEEN NOT 100 AND 200 C. Where 价格 NOT BETWEEN 101 AND

Oracle高级复制配置手册_业务广告_.doc

<4D F736F F D20C9CFBAA3CAD0BCC6CBE3BBFAB5C8BCB6BFBCCAD4C8FDBCB6BFBCCAD4B4F3B8D95FBDA8D2E9B8E55F5F E646F63>

数 据 库 管 理 第 章 (1) 创 建 一 个 简 单 的 表 空 间 Create tablespace user1 datafile 'e:\database\oracle\user1_data.dbf' size 00M; () 指 定 数 据 文 件 的 可 扩 展 性 Create t

PowerPoint Presentation

3. 教学重点和难点教学重点 : 数据管理的三个阶段及特点 三种主要模型 E-R 图 DBS 体系结构 教学难点 :E-R 图 (1) 数据库系统概论主要知识点 : 数据 数据库 数据库管理系统 数据库系统 数据管理技术的产生和发展 数据库系统的特点 (2) 数据模型主要知识点 : 数据模型要素 概

11.2 overview

教学重点 : 数据管理的三个阶段及特点 三种主要模型 E-R 图 DBS 体系结构 教学难点 :E-R 图 (1) 数据库系统概论主要知识点 : 数据 数据库 数据库管理系统 数据库系统 数据管理技术的产生和发展 数据库系统的特点 (2) 数据模型主要知识点 : 数据模型要素 概念模型 层次模型 网

DR2010.doc

01 SQL Server SQL Server 2008 SQL Server 6-1 SSIS SQL Server ( master ) ( msdb ) SQL Server ( master ) master 6-1 DTS sysadmin 6-1 sysa

第三章 SQL语言

帝国CMS下在PHP文件中调用数据库类执行SQL语句实例

4. 设有学生表 ( 学号, 姓名, 所在系, 身份证号 ) 和系表 ( 系名, 系办公地点儿下列关于两个 表的引用关系的描述, 正确的是 ( ) A. 设置学生表中的 " 所在系 " 为外键 B. 设置系表中的 " 系名 " 为外键 C. 设置学生表的学号为主键 D. 元法表达这两个表的引用关系

<4D F736F F F696E74202D20B5DABEC5D5C220CAFDBEDDBFE2B0B2C8ABD0D42D6E6577>

三. 发现表被删除, 开始着手解决 1. 该表所在表空间离线 ( 确保删除表所在位置不会被重写 ) SQL> alter tablespace raw_odu offline; Tablespace altered. 2. 通过 logmnr, 找出被删除的数据 data _object _id 1

Microsoft Word - SupplyIT manual 3_cn_david.doc

Microsoft Word - Sailor-SQL-Exercise.doc

使用SQL Developer

幻灯片 1

Microsoft Word - Front cover_white.doc

标题

Oracle Database 10g: SQL (OCE) 的第一堂課

设计一个学生管理关系数据库,包括学生关系、课程关系和选课关系

0SQL SQL SQL SQL SQL 3 SQL DBMS Oracle DBMS DBMS DBMS DBMS RDBMS R DBMS 2 DBMS RDBMS R SQL SQL SQL SQL SELECT au_fname,au_ lname FROM authors ORDER BY

Transcription:

本章的知识点了解 SQL 语言发展史掌握关系数据库体系结构 三层结构在关系数据库体现 ) 掌握基本表定义 包括修改 删除定义 ) 掌握视图的概念与定义 删除定义理解索引的概念与定义 删除定义总结 SQL 数据定义的特点总结用户数据查询的基本结构掌握 SELECT 子句重复元组的处理掌握 FROM 子句掌握 WHERE 子句理解更名 属性 列 ) 运算理解字符串操作理解元组显示顺序理解分组掌握聚集函数掌握空值处理理解嵌套子查询的概念 表达理解掌握集合成员资格了解集合之间的比较了解集合基数的测试

了解派生关系掌握关系的连接掌握用户数据插入掌握用户数据删除掌握用户数据更新了解通过视图更新用户数据总结 SQL 语言特点需重点理解掌握的内容 : 数据定义 基本表 视图 ) 数据查询 基本结构及其各种变化 ) 数据更新 如何证明 SQL 语句的正确性?

作业参考答案 : /*P148 习题 3 创建表 s p j spj*/ -- 创建之前首先删除可能存在的表 --spj 表参考表 s p j, 应该先删除 drop table spj; drop table s; drop table p; drop table j; create table s sno char2), sname varchar29), status number2), city varchar29) create table p pno char2), pname varchar29), color char3), weight number4) create table j jno char2), jname varchar212), city varchar29) create table spj sno char2), pno char2), jno char2), qty number4) /*P148 习题 4*/ /*1)*/ -- 按照关系代数转换查询 select distinct sno from spj where jno = 'J1'; /*2)*/ -- 按照关系代数转换查询

select distinct sno from spj where jno = 'J1' and pno = 'P1'; /*3)*/ --natural join 连接查询 select distinct sno from spj natural join p where jno = 'J1' and color = ' 红 ' ; --join 连接查询 select distinct sno from spj inner join p on spj.pno = p.pno where jno = 'J1' and color = ' 红 ' ; select distinct sno from spj where jno = 'J1' and pno in select pno from p where color = ' 红 ' select distinct sno from spj, p where spj.pno = p.pno and jno = 'J1' and color = ' 红 ' ; -- 子查询 exists select distinct sno from spj where jno = 'J1' and exists select pno from p where color = ' 红 ' and p.pno = spj.pno /*4)*/ --natural join 连接查询 select distinct jno from j where jno not in select jno from spj natural join p natural join s where city = ' 天津 ' and color = ' 红 ' -- 将 not in 改用 not exists, 下面几种方法的语句同样可以如此改写, 不再一一列出 select distinct jno from j where not exists select jno from spj natural join p natural join s where city=' 天津 ' and color=' 红 ' and spj.jno = j.jno --join 连接查询 select distinct jno from j where jno not in select jno from spj inner join p on spj.pno=p.pno inner join s on spj.sno=s.sno where city = ' 天津 ' and color = ' 红 ' select distinct jno from j where jno not in select jno from spj where sno in select sno from s where city = ' 天津 ') and pno in select pno from p where color = ' 红 ') select distinct jno from j where jno not in select jno from spj,p,s where spj.pno=p.pno and spj.sno=s.sno and city = ' 天津 ' and color = ' 红 ' /*5)*/ -- 按照关系代数转换查询

select distinct jno from spj spjx where not exists select pno from spj where sno = 'S1' and pno not in select pno from spj spjz where spjz.jno = spjx.jno ) select distinct jno from spj spjx where not exists select * from spj spjy where sno = 'S1' and not exists select * from spj spjz where spjx.jno = spjz.jno and spjz.pno = spjy.pno) /*P148 习题 5*/ /*1)*/ select sname,city from s; /*2)*/ select pname,color,weight from p; /*3)*/ select distinct jno from spj where sno = 'S1'; /*4)*/ -- 只按照题意, 不考虑工程使用不同供应商供应的同种零件 -- 只考虑 natural join 查询 select distinct pname,qty from spj natural join p where jno = 'J2'; -- 考虑工程使用不同供应商供应的同种零件, 直接按照零件名分组 select distinct pname,sumqty) as sumqty from spj natural join p where jno = 'J2' group by pname; -- 考虑工程使用不同供应商供应的同种零件, 考虑到零件同名, 按照零件号分组 select pname,sumqty from p natural join select pno, sumqty) as sumqty from spj where jno = 'J2' group by pno) j2sumqty ; /*5)*/ --natural join 查询 select distinct pno from spj natural join s where city = ' 上海 '; --join 查询 select distinct pno from spj inner join s on spj.sno=s.sno where city = ' 上海 '; select distinct pno from spj,s where spj.sno = s.sno and city = ' 上海 '; select distinct pno from spj where sno in select sno from s where city = ' 上海 ' -- 子查询 exists select distinct pno from spj where exists select sno from s where city = ' 上海 'and s.sno = spj.sno /*6)*/ --natural join 查询 select distinct jname from spj natural join s natural join j where s.city = ' 上海 '; --join 查询

select distinct jname from spj inner join s on spj.sno = s.sno inner join j on spj.jno = j.jno where s.city = ' 上海 '; select distinct jname from spj,s,j where spj.jno = j.jno and spj.sno = s.sno and s.city = ' 上海 '; select distinct jname from j where jno in select jno from spj where sno in select sno from s where city = ' 上海 ') -- 子查询 exists select distinct jname from j where existsselect * from spj inner join s on spj.sno = s.sno where city = ' 上海 ' and spj.jno = j.jno /*7)*/ -- 本题不考虑没有使用零件的工程 --natural join 查询 select distinct jno from spj where jno not in select jno from spj natural join s where city = ' 天津 ' --join 查询 select distinct jno from spj where jno not in select jno from spj inner join s on spj.sno = s.sno where city = ' 天津 ' select distinct jno from spj where jno not in select jno from spj, s where spj.sno = s.sno and city = ' 天津 ' select distinct jno from spj where jno not in select jno from spj where sno in select sno from s where city = ' 天津 ') -- 子查询 exists select distinct jno from spj spjx where not exists select * from spj spjy where spjx.jno = spjy.jno and sno in select sno from s where city = ' 天津 ') -- 错误 select distinct jno from spj where sno not in select sno from s where city = ' 天津 ') -- 下面考虑没有使用零件的工程, 按照关系代数转换查询 select distinct jno from j where jno not in select jno from spj inner join s on spj.sno = s.sno where city = ' 天津 /*8)*/ update p set color = ' 蓝 ' where color = ' 红 '; /*9)*/ update spj set sno = 'S3' where sno = 'S5' and pno = 'P6' and jno = 'J4'; /*10)*/ -- 考虑到 spj 参考引用 s, 先删除 spj 内容 delete from spj where sno = 'S2';

delete from s where sno = 'S2'; /*11)*/ insert into spjsno,jno,pno,qty) values's2','j6','p4',200 insert into spj values's2','p4','j6',200 /*P149 习题 11*/ drop view v_sj; create view v_sj as select sno, pno,qty from spj natural join j where jname = ' 三建 '; create view v_sj as select sno, pno,qty from spj inner join j on spj.jno = j.jno where jname = ' 三建 '; create view v_sj as select sno, pno, qty from spj where jno in select jno from j where jname = ' 三建 ' --1) select pno, sumqty) as qty from v_sj group by pno; --2) select * from v_sj where sno = 'S1'; -- 证明第一章 10 -- 定义表 drop table sp; create table sp sno char2), pno char2), primary key sno,pno) drop table pj ; create table pj pno char2), jno char2), primary key pno,jno) drop table sj; create table sj sno char2),

jno char2), primary key sno,jno) -- 插入数据 insert sp select distinct sno,pno from spj; insert sj select distinct sno,jno from spj; insert pj select distinct pno,jno from spj; -- 结果 select sp.sno,sp.pno,sj.jno from sp natural join sj natural join pj order by sp.sno,sp.pno,sj.jno ; -- 结果比较 select sno, pno, jno from spj order by sno, pno, jno ;