[每日一题] OCP1z0-047 :2013-08-28 DELETE..........................................................160
转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/10475707
正确答案:ACD
根据题库,操作如下:
A答案能删除:
oe@OCM> delete from order_items
2 WHERE order_id IN (SELECT order_id FROM orders
3 WHERE order_status IN(0,1)); 110 rows deleted. oe@OCM> rollback; Rollback complete.
B答案不能删除:没有这样的语法(DELETE * FROM,即DELETE后直接跟表名,而不能用*)
oe@OCM> DELETE *
2 FROM order_items
3 WHERE order_id IN(SELECT order_id
4 FROM orders
5 WHERE orders
6 WHERE order_status IN(0,1));
DELETE *
*
ERROR at line 1:
ORA-00903: invalid table name
C答案能删除:
oe@OCM> delete from order_items i
2 WHERE order_id=(SELECT order_id FROM orders o
3 WHERE i.order_id=o.order_id AND
4 order_status IN(0,1)); 110 rows deleted. oe@OCM> rollback; Rollback complete.
D答案也能删除:
oe@OCM> delete from(select * from order_items i,orders o
2 WHERE i.order_id=o.order_id AND order_status in(0,1)); 110 rows deleted.
分析D能删除的原因:
1、ORDERS表有主键ORDER_ID:CONSTRAINT "ORDER_PK" PRIMARY KEY ("ORDER_ID")。
看下面红色字体:
oe@OCM> select dbms_metadata.get_ddl('TABLE','ORDERS') from dual; DBMS_METADATA.GET_DDL('TABLE','ORDERS')
-------------------------------------------------------------------------------- CREATE TABLE "OE"."ORDERS"
( "ORDER_ID" NUMBER(12,0),
"ORDER_DATE" TIMESTAMP (6) WITH LOCAL TIME ZONE CONSTRAINT "ORDER_DATE_NN" NOT NULL ENABLE,
"ORDER_MODE" VARCHAR2(8),
"CUSTOMER_ID" NUMBER(6,0) CONSTRAINT "ORDER_CUSTOMER_ID_NN" NOT NULL ENABLE,
"ORDER_STATUS" NUMBER(2,0),
"ORDER_TOTAL" NUMBER(8,2),
"SALES_REP_ID" NUMBER(6,0),
"PROMOTION_ID" NUMBER(6,0),
CONSTRAINT "ORDER_MODE_LOV" CHECK (order_mode in ('direct','online')) ENABLE,
CONSTRAINT "ORDER_TOTAL_MIN" CHECK (order_total >= 0) ENABLE,
CONSTRAINT "ORDER_PK" PRIMARY KEY ("ORDER_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS NOLOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "EXAMPLE" ENABLE,
CONSTRAINT "ORDERS_SALES_REP_FK" FOREIGN KEY ("SALES_REP_ID")
REFERENCES "HR"."EMPLOYEES" ("EMPLOYEE_ID") ON DELETE SET NULL ENABLE,
CONSTRAINT "ORDERS_CUSTOMER_ID_FK" FOREIGN KEY ("CUSTOMER_ID")
REFERENCES "OE"."CUSTOMERS" ("CUSTOMER_ID") ON DELETE SET NULL ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS NOLOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "EXAMPLE"
2、ORDER_TIEMS表有外键ORDER_ID:CONSTRAINT "ORDER_ITEMS_ORDER_ID_FK" FOREIGN KEY ("ORDER_ID")
REFERENCES "OE"."ORDERS" ("ORDER_ID") ON DELETE CASCADE ENABLE NOVALIDATE,并加上了主外键可以级联删除。
看下面红色字体:
oe@OCM> select dbms_metadata.get_ddl('TABLE','ORDER_ITEMS') from dual; DBMS_METADATA.GET_DDL('TABLE','ORDER_ITEMS')
-------------------------------------------------------------------------------- CREATE TABLE "OE"."ORDER_ITEMS"
( "ORDER_ID" NUMBER(12,0),
"LINE_ITEM_ID" NUMBER(3,0) NOT NULL ENABLE,
"PRODUCT_ID" NUMBER(6,0) NOT NULL ENABLE,
"UNIT_PRICE" NUMBER(8,2),
"QUANTITY" NUMBER(8,0),
CONSTRAINT "ORDER_ITEMS_PK" PRIMARY KEY ("ORDER_ID", "LINE_ITEM_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS NOLOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "EXAMPLE" ENABLE,
CONSTRAINT "ORDER_ITEMS_ORDER_ID_FK" FOREIGN KEY ("ORDER_ID")
REFERENCES "OE"."ORDERS" ("ORDER_ID") ON DELETE CASCADE ENABLE NOVALIDATE,
CONSTRAINT "ORDER_ITEMS_PRODUCT_ID_FK" FOREIGN KEY ("PRODUCT_ID")
REFERENCES "OE"."PRODUCT_INFORMATION" ("PRODUCT_ID") ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS NOLOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "EXAMPLE"
删除了子表上的记录:
oe@OCM> select count(*) from orders; --主表 COUNT(*)
----------
105 oe@OCM> select count(*) from order_items; --子表 COUNT(*)
----------
665 oe@OCM> delete from(select * from order_items i,orders o
2 WHERE i.order_id=o.order_id AND order_status in(0,1)); 110 rows deleted. oe@OCM> select count(*) from orders; --记录没变 COUNT(*)
----------
105 oe@OCM> select count(*) from order_items; --记录少了110条 COUNT(*)
----------
555
有些人D答案百思不得期解,模拟这个操作时一直报错(ERROR at line 1:
ORA-01752: cannot delete from view without exactly one key-preserved table)原因就在于自己去建了两个表order和order_items时没有在这两个表上建约束主外键,并且加上主外键可以级联删除(CONSTRAINT "ORDER_ITEMS_ORDER_ID_FK" FOREIGN KEY ("ORDER_ID") REFERENCES "OE"."ORDERS" ("ORDER_ID") ON DELETE CASCADE ENABLE NOVALIDATE)。
这个我就不再测试了,太简单了。
QQ:252803295
学习交流QQ群:
DSI&Core Search Ⅰ 群:127149411(技术:已满)
DSI&Core Search Ⅱ 群:177089463(技术:未满)
DSI&Core Search Ⅲ 群:284596437(技术:未满)
DSI&Core Search Ⅳ 群:192136702(技术:未满)
DSI&Core Search Ⅴ 群:285030382(闲聊:未满)
MAIL:oracledba_cn@hotmail.com
BLOG: http://blog.csdn.net/guoyjoe
WEIBO:http://weibo.com/guoyJoe0218
ITPUB: http://www.itpub.net/space-uid-28460966.html
OCM: http://education.oracle.com/education/otn/YGuo.HTM
[每日一题] OCP1z0-047 :2013-08-28 DELETE..........................................................160的更多相关文章
- 老男孩IT教育-每日一题汇总
老男孩IT教育-每日一题汇总 第几天 第几周 日期 快速访问链接 第123天 第二十五周 2017年8月25日 出现Swap file….already exists以下错误如何解决? 第122天 2 ...
- PL/SQL Challenge 每日一题:2014-3-14 11gR2中带RELIES_ON子句的RESULT_CACHE函数
PL/SQL Challenge 每日一题:2014-3-14 11gR2中带RELIES_ON子句的RESULT_CACHE函数 最先答对且答案未经编辑的puber将获得纪念章一枚(答案不可编辑但可 ...
- LeetCode 每日一题「判定字符是否唯一」
我是陈皮,一个在互联网 Coding 的 ITer,微信搜索「陈皮的JavaLib」第一时间阅读最新文章,回复[资料],即可获得我精心整理的技术资料,电子书籍,一线大厂面试资料和优秀简历模板. 题目 ...
- 【Java每日一题】20170106
20170105问题解析请点击今日问题下方的"[Java每日一题]20170106"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...
- 【Java每日一题】20170105
20170104问题解析请点击今日问题下方的"[Java每日一题]20170105"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...
- 【Java每日一题】20170104
20170103问题解析请点击今日问题下方的"[Java每日一题]20170104"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...
- 【Java每日一题】20170103
20161230问题解析请点击今日问题下方的"[Java每日一题]20170103"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...
- 【Java每日一题】20161230
// 20161229问题解析请点击今日问题下方的"[Java每日一题]20161230"查看(问题解析在公众号首发,公众号ID:weknow619)package Dec2016 ...
- 【Java每日一题】20161229
package Dec2016; import java.util.ArrayList; import java.util.List; public class Ques1229 { public s ...
- 【Java每日一题】20161228
package Dec2016; import java.util.ArrayList; import java.util.List; public class Ques1228 { public s ...
随机推荐
- c#关于委托和事件
using System; using System.Collections.Generic; using System.Text; namespace Delegate { // 热水器 ...
- linux c 得到文件大小
#include <sys/stat.h> unsigned long get_file_size(const char *path) { unsigned long filesize = ...
- KVM客户机使用主机USB设备
有些时候KVM客户机还是要使用USB设备,比如USB密钥等 KVM命令行参数 -usb 打开usb驱动程序,启动客户机usb支持 -usbdevice devname 为客户机增加usb设备,devn ...
- ios创建画笔的样例(双笔画效果)
定义一个UIView:主要是在这个View里面加一个UIImageView,绘图都在这个UIImageView里面进行 @property(nonatomic) CGPoint prePoint; / ...
- 2014Esri全球用户大会之标准和互操作
1. ArcGIS是一个开放协作的平台吗?Esri是怎样看待"开放"的? 是的,ArcGIS是一个开放协作的平台.Esri公司致力于支持我们的用户更加easy的在异构环境下工作 ...
- Linux内核源代码解析之——我与神童聊Linux内核
本文原创为freas_1990,转载请标明出处:http://blog.csdn.net/freas_1990/article/details/11619609 我的朋友里,至少有2.5个神童. 有的 ...
- 下载并在Eclipse中关联Android源代码
大家都知道文档写的好当然让人非常舒服,可是有时候文档再好也不如直接看源代码来的直接,既然Android是开源的,为什么不在eclipse里直接看它的源代码呢? 1.下载源代码 这部分网上有大量的资料, ...
- java序列化对象 插入、查询、更新到数据库
java序列化对象 插入.查询.更新到数据库 : 实现代码例如以下: import java.io.ByteArrayInputStream; import java.io.ByteArrayOutp ...
- android JB2连拍降速原理介绍
1.HAL层 (1)alps\mediatek\platform\mt6589\hardware\camera\core\camshot\MultiShot\MultiShot.cpp sleep实现 ...
- C++常变量
在定义变量时,如果加上关键字const,则变量的值在程序运行期间不能改变,这种变量称为常变量(constant variable).例如: const int a=3; //用const来声明 ...