没有合适的资源?快使用搜索试试~ 我知道了~
首页深入理解SQL:语法与高效执行指南
深入理解SQL:语法与高效执行指南
![](https://csdnimg.cn/release/wenkucmsfe/public/img/star.98a08eaa.png)
"《SQL Clearly Explained》第三版是一本专为初学者设计的深入介绍SQL语言的教程。作者Jan L. Harrington以一种温和而全面的方式引领读者学习,本书不仅涵盖了SQL语法规则,还着重讲解了SQL的工作原理。理解“如何”执行SQL语句与仅仅知道“是什么”同样重要,这将帮助读者编写出执行效率极高的SQL语句。 该书由Morgan Kaufmann出版社出版,作为Elsevier旗下的一个品牌,它承诺使用环保的无酸纸张,确保阅读体验的同时,关注可持续性。版权方面,所有内容未经书面许可不得复制或传播,无论是电子形式还是机械方式,如影印、录音或任何信息存储和检索系统。关于获取许可的详细信息,包括如何申请许可以及与Copyright Clearance Center和Copyright Licensing Agency等组织的合作政策,可以在出版社的官方网站上查询:www.elsevier.com/permissions。 书中强调,知识和实践领域不断演变,随着新的研究和实践经验的积累,研究方法、专业实践或医疗治疗可能会有所变化。因此,读者在学习过程中应保持更新,跟随最佳实践的发展,以适应这个快速发展的技术领域。《SQL Clearly Explained》不仅是学习者掌握SQL基础的实用指南,也是他们跟上SQL技术进步的重要参考书。"
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/2354783/bg10.jpg)
Relations and Tables 9
Why are unique primary keys so important? Because they en-
sure that you can retrieve every piece of data that you put into
a database. If primary keys aren’t unique, a query will retrieve
one or more rows with a value you specify, but you can’t be cer-
tain which is the exact row you want unless you know some-
thing that identies just that one row. In fact, you should be
able to retrieve any single data value knowing three things: the
name of the table, the name of the column, and the primary
key of the row.
As you will see later in this book, you specify a table’s primary
key when you dene the table to the DBMS. e DBMS will
then enforce a constraint that requires unique primary key
values.
Note: It is actually possible to create a table that has no primary
key, but some DBMSs won’t let you put any data in it.
Sometimes you don’t put data in some columns of some rows
because you don’t know the appropriate data values. e empty
columns don’t contain a zero or a blank. Instead, they contain
a special indicator known as null, which means “unknown.”
ere are two important implications of the presence of nulls
in a table. First, we can’t allow nulls as all or part of a primary
key. If there is only one row with null for a primary key, then
the property of unique primary key values is preserved. e
minute we introduce a second row with a null primary key,
however, the primary keys are no longer unique. A DBMS will
therefore ensure that all primary keys have values, a constraint
known as entity integrity.
Secondly, nulls can aect the result of queries. Assume, for
example, that you want to retrieve the names of all employees
who have a salary of more than $100,000. For all employees
that have a value in the salary column, the answer to “Is the
salary more than $100,000” will be either “yes” or “no.” But if
Nulls
![](https://csdnimg.cn/release/download_crawler_static/2354783/bg11.jpg)
10 Chapter 1: The Relational Data Model
the salary column contains null, the DBMS doesn’t know the
answer to the question; the result is “maybe.”
We say that a DBMS operates using three-valued logic: yes,
no, or maybe. e question that remains is what a DBMS
should do when the answer to the question it is asking is “may-
be.” Should it retrieve rows with null or leave them out? e
relational data model doesn’t specify exactly what a DBMS
should do, but does require the DBMS to act consistently—
either always retrieve rows with nulls or always leave them
out—and that the user be aware of what is happening. We’ll
deal with eect of nulls at various places throughout this book.
ere are two primary types of tables with which you will be
working when you use SQL. e tables that contain data that
are stored in the database are known as base tables. However,
the DBMS also uses several types of temporary tables that only
exist in main memory. ese are virtual tables and by deni-
tion they are not stored in the database. Most modern DBMS
use several types of virtual tables, including views, temporary
tables, and query result tables. If you want to keep the data in a
virtual table, then those data must be inserted into a base table.
Along with data describing entities, a database must somehow
represent relationships between entities. Prior to the relational
data model, databases used data structures embedded in the
data to show relationships. However, the relational data model
relies on it data to show relationships.
ere are three types of relationships between entities that we
encounter in our database environments: one-to-one, one-to-
many, and many-to-many.
A one-to-one relationship exists between two entities when an
occurrence of entity A is related to zero or one occurrences of
entity B and an occurrence of entity B is related to zero or one
occurrences of entity A. Although the specic occurrences in-
volved in the relationship may change over time, there is never
Base versus Virtual
Tables
Representing
Relationships
Types of
Relationships
One-to-One Relationships
![](https://csdnimg.cn/release/download_crawler_static/2354783/bg12.jpg)
Representing Relationships 11
more than one related occurrence at any given time. For ex-
ample, a car and its engine have unique serial numbers. At any
one time, an engine is installed in only one car; at the same
time, a car has only one engine. e engine may be in no car
or it can be moved from one car to another, but it can’t be in
more than one place at a time. By the same token, a car can
have no engine or one engine. e specic engine may change
over time but there is never more than one.
4
We include a relationship in an ERD by drawing a line be-
tween the rectangles for two related entities. e line ends
identify the type of the relationship. In Figure 1-5 you can see
the way in which we would diagram the one-to-one relation-
ship between a car and its engine. e |0 at the end of the line
means “zero or one.”
If the relationship is required (mandatory), then the |0 at the
end of the line changes to || (one and only one). We use man-
datory relationships when we don’t want an occurrence of an
entity to be store in the database unless it is related to an oc-
currence of the entity at the other end of the relationship. For
example, if we didn’t want an engine in the database unless
that engine was in a car, the end of the line next to the car
entity would be ||.
True one-to-one relationships are very uncommon, but da-
tabase environments are full of one-to-many relationships.
When a one-to-many relationship exists between two entities,
one occurrence of entity A is related to zero, one, or more oc-
currences of entity B; each occurrence of entity B is related to
at most one occurrence of entity A. If, for example, we add car
owners to our car database, then there will be a one-to-many
4
Yes, there is at least one exception to the statement that a car has only
one engine: hybrids have a gasoline engine and an electric engine. ere
are exceptions to just about every scenario in this book, so please take
them in the spirit in which they were intended: as examples.
One-to-many Relationships
![](https://csdnimg.cn/release/download_crawler_static/2354783/bg13.jpg)
12 The Relational Data Model
relationship between an owner and a car. At any time, a person
can own zero, one, or more cars and a car belongs to zero or
one owners.
Figure 1-5: A one-to-one relationship
In an ERD, the line between the related entities has |0 or ||
at one end, representing the zero, one, or more end of the
relationship (or one and only one in the case of a mandatory
relatioship). e end of the line at the “many” side of the re-
lationship is marked with >0 or >|, representing zero, one, or
more (or in the case of a mandatory relationship, one or more).
In Figure 1-6, the owner entity is at the “one” end of the rela-
tionship and the car entity is at the “many” end.
Chapter 1:
![](https://csdnimg.cn/release/download_crawler_static/2354783/bg14.jpg)
Representing Relationships 13
Figure 1-6: Adding a one-to-many relationship
e third type of relationship between entities, a many-to-
many relationship, is also very common. When two entities are
related in that way, one occurrence of entity A can be related
to many occurrences of entity B (zero, one, or more) and one
occurrence of entity B can be related to many occurrences of
entity A. To demonstrate, let’s add an entity for a Web site to
the car database, indicating which cars are advertised on which
Web sites. A car can be advertised on many Web sites and a site
can advertise many cars.
e many-to-many relationship has been diagrammed in Fig-
ure 1-7. Notice that each end of the line connecting the Web
site and Car entities has the “many” symbol, >0.
Many-to-many
Relationships
剩余446页未读,继续阅读
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/default.jpg!1)
railwaycatty
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
会员权益专享
最新资源
- VMP技术解析:Handle块优化与壳模板初始化
- C++ Primer 第四版更新:现代编程风格与标准库
- 计算机系统基础实验:缓冲区溢出攻击(Lab3)
- 中国结算网上业务平台:证券登记操作详解与常见问题
- FPGA驱动的五子棋博弈系统:加速与创新娱乐体验
- 多旋翼飞行器定点位置控制器设计实验
- 基于流量预测与潮汐效应的动态载频优化策略
- SQL练习:查询分析与高级操作
- 海底数据中心散热优化:从MATLAB到动态模拟
- 移动应用作业:MyDiaryBook - Google Material Design 日记APP
- Linux提权技术详解:从内核漏洞到Sudo配置错误
- 93分钟快速入门 LaTeX:从入门到实践
- 5G测试新挑战与罗德与施瓦茨解决方案
- EAS系统性能优化与故障诊断指南
- Java并发编程:JUC核心概念解析与应用
- 数据结构实验报告:基于不同存储结构的线性表和树实现
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)