oracle 每日一题-数据库约束
来源:互联网 发布:精通matlab最优化计算 编辑:程序博客网 时间:2024/05/22 10:45
以往旧题索引:
http://www.itpub.net/forum.php?m ... eid&typeid=1808
原始出处:
http://www.plsqlchallenge.com/
作者: ChrisSaxon
运行环境:SQLPLUS, SERVEROUTPUT已打开
你已开始处理新应用程序。它在这些表中存储订单明细:
create table plch_customers (
customer_id int not null
primary key,
customer_name varchar2(255) not null
unique
);
create table plch_orders (
order_id int not null
primary key,
order_datetime date not null,
customer_id int not null
references plch_customers ( customer_id )
);
create table plch_order_items (
order_id int not null
references plch_orders ( order_id ),
item_number int not null
check ( item_number between 1 and 5 ),
product_id int not null,
unit_cost number(10, 2) not null,
quantity int not null,
primary key ( order_id, item_number ),
check ( ( unit_cost * quantity ) > 0 )
);
给定这个模式,下列哪个说法是正确的?
(A)
所有的客户(plch_customers)都必须有不同的名字。
(B)
每个订单(plch_orders)有且仅有一位客户。
(C)
在给定的日期和时间,一名客户仅能下一个订单。
(D)
在一个订单内,最多只能有五种不同产品。
(E)
http://www.itpub.net/forum.php?m ... eid&typeid=1808
原始出处:
http://www.plsqlchallenge.com/
作者: ChrisSaxon
运行环境:SQLPLUS, SERVEROUTPUT已打开
你已开始处理新应用程序。它在这些表中存储订单明细:
create table plch_customers (
customer_id int not null
primary key,
customer_name varchar2(255) not null
unique
);
create table plch_orders (
order_id int not null
primary key,
order_datetime date not null,
customer_id int not null
references plch_customers ( customer_id )
);
create table plch_order_items (
order_id int not null
references plch_orders ( order_id ),
item_number int not null
check ( item_number between 1 and 5 ),
product_id int not null,
unit_cost number(10, 2) not null,
quantity int not null,
primary key ( order_id, item_number ),
check ( ( unit_cost * quantity ) > 0 )
);
给定这个模式,下列哪个说法是正确的?
(A)
所有的客户(plch_customers)都必须有不同的名字。
(B)
每个订单(plch_orders)有且仅有一位客户。
(C)
在给定的日期和时间,一名客户仅能下一个订单。
(D)
在一个订单内,最多只能有五种不同产品。
(E)
在订单中,单价(unit_cost) 或者 数量(quantity) 都不可能为负数
NUMBER ( precision, scale)
scale表示数字小数点右边的位数,scale默认设置为0. 如果把scale设成负数,Oracle将把该数字取舍到小数点左边的指定位数。
check ( item_number between 1 and 5 ),
check ( ( unit_cost * quantity ) > 0 )
references plch_customers ( customer_id )
A: customer_name上有一个唯一键。所以这会禁止你在两行数据存储相同的客户名字。
B: 从plch_orders到plch_customers有一个非空的外键。所以你必须存储一个在plch_customers上存在的customer_id。在plch_orders上只有一个客户列,所以你不能在一个订单上有多个客户。
C: 不对!在( customer_id, order_datetime )上并没有一个唯一键或者主键。所以你可以在两行上为这些列存储相同的值。
D: 是的。Plch_order_items.item_number是一个整数,有一个校验约束来确保这个数值在1和5之间。所以你在这个列能够存储的值只有1, 2, 3, 4 或者 5。 和order_id一起,这个列构成了表的主键。所以给定一个order_id, 你只能够存储一次这些值。因此对一个订单来说,物品的数量最多为五。每个订单物品对应一种产品。所以你在一个订单上最多只能有五种产品!
E:不对!单价(unit_cost) 和数量(quantity)的乘积必须大于零。但是如果你把两个负数相乘,结果是正数。所以你可以存储一个订单物品,其单价和数量都为负数!
0 0
- oracle 每日一题-数据库约束
- oracle 每日一题-引用约束(1)、用约束改善性能(2)
- [每日一题] OCP1z0-047 :2013-08-03 约束―――延迟约束....................................................23
- Oracle数据库完整性约束
- oracle数据库约束
- oracle数据库约束
- Oracle数据库的约束
- oracle数据库约束类型
- oracle数据库添加约束
- oracle 数据库的约束
- Oracle数据库之约束
- Oracle数据库中的约束
- 修改oracle数据库约束
- oracle数据库之约束
- Oracle数据库表约束
- Oracle数据库完整性约束
- Oracle数据库表约束
- oracle数据库(约束)
- OSI七层与TCP/IP五层网络架构详解
- 深度学习对抗样本的八个误解与事实
- springmvc框架原理
- Java--封装(encapsulation)和private关键字
- Git 工作区和暂存区
- oracle 每日一题-数据库约束
- 关于Android应用程序改包名,生成新的一个apk的一些关注点~~
- release and lib correspondence
- Android中的应用启动方式及优化
- Octave 入门语法
- Jekins 无法连接网络,手动安装插件,git插件
- 新版chrome查看https数字证书方式改变
- 7月28日--JavaScript进阶篇
- Java sun.misc.Unsafe 和 CAS