SQL in A Nutshell, 4th Edition Kevin Kline Instant Download
SQL in A Nutshell, 4th Edition Kevin Kline Instant Download
install download
https://ebookmeta.com/product/sql-in-a-nutshell-4th-edition-
kevin-kline/
https://ebookmeta.com/product/sql-in-a-nutshell-4th-edition-
third-early-release-kevin-kline-regina-o-obe/
https://ebookmeta.com/product/python-in-a-nutshell-4th-edition-
alex-martelli/
https://ebookmeta.com/product/consumer-protection-law-in-a-
nutshell-4th-edition-dee-pridgen-gene-marsh/
https://ebookmeta.com/product/charlie-s-good-tonight-the-life-
the-times-and-the-rolling-stones-the-authorized-biography-of-
charlie-watts-1st-edition-paul-sexton/
Dessert Cookbook: A Dessert Cookbook with Delicious
Dessert Recipes 1st Edition Booksumo Press
https://ebookmeta.com/product/dessert-cookbook-a-dessert-
cookbook-with-delicious-dessert-recipes-1st-edition-booksumo-
press/
https://ebookmeta.com/product/youre-a-mean-one-matthew-prince-
boy-meets-boy-2-1st-edition-timothy-janovsky-2/
https://ebookmeta.com/product/all-or-none-cooperation-and-
sustainability-in-italy-s-red-belt-anthropology-of-europe-3-1st-
edition-alison-sanchez-hall/
https://ebookmeta.com/product/beginning-algebra-6th-edition-
miller/
https://ebookmeta.com/product/food-chemistry-the-role-of-
additives-preservatives-and-adulteration-1st-edition-mousumi-sen/
In the Moment: Build Your Confidence, Communication and
Creativity at Work 1st Edition Neil Mullarkey
https://ebookmeta.com/product/in-the-moment-build-your-
confidence-communication-and-creativity-at-work-1st-edition-neil-
mullarkey/
SQL in a Nutshell
A Desktop Quick Reference
With Early Release ebooks, you get books in their earliest form—the author’s
raw and unedited content as they write—so you can take advantage of these
technologies long before the official release of these titles.
In the early 1970s, the seminal work of IBM research fellow Dr. E. F.
Codd led to the development of a relational data model product
called SEQUEL, or Structured English Query Language . SEQUEL
ultimately became SQL, or Structured Query Language .
IBM, along with other relational database vendors, wanted a
standardized method for accessing and manipulating data in a
relational database. Although IBM was the first to develop relational
database theory, Oracle was first to market the technology. Over
time, SQL proved popular enough in the marketplace to attract the
attention of the American National Standards Institute (ANSI) in
cooperation with the International Standards Organization (ISO),
which released standards for SQL in 1986, 1989, 1992, 1999, 2003,
2006, 2011, and 2016.
Since 1986, various competing languages have allowed developers
to access and manipulate relational data. However, few were as easy
to learn or as universally accepted as SQL. Programmers and
administrators now have the benefit of being able to learn a single
language that, with minor adjustments, is applicable to a wide
variety of database platforms, applications, and products.
SQL in a Nutshell , Fourth Edition, provides the syntax for five
common implementations of SQL:
The ANSI/ISO SQL standard
PostgreSQL version 13
6. Views must show the updates of their base tables and vice
versa.
12. Any row processing done in the system must obey the same
integrity rules and constraints that set-processing operations
do.
These principles continue to be the litmus test used to validate the
“relational” characteristics of a database platform; a database that
does not meet all of these rules is not fully relational. While these
rules do not apply to applications development, they do determine
whether the database engine itself can be considered truly
“relational.” Currently, most commercial RDBMS products pass Codd’s
test. All platforms discussed in the reference material of SQL in a
Nutshell , Fourth Edition satisfy these requirements, while the most
prominent NoSQL data platforms are discovered in Chapter 9.
Understanding Codd’s principles assists developers in the proper
development and design of relational databases (RDBs). The
following sections detail how some of these requirements are met
within SQL using RDBs.
NOTE
The ANSI/ISO standard does not say how data should be sorted, only
that platforms must provide common collations found in a given
language.
NULLs (rule 3)
Most databases allow any of their supported data types to store
NULL values. Inexperienced SQL developers tend to think of NULL as
zero or blank. In fact, NULL is neither of these. In SQL, NULL literally
means that the value is unknown or indeterminate. (This question
alone—whether NULL should be considered unknown or
indeterminate—is the subject of much academic debate.) This
differentiation enables a database designer to distinguish between
those entries that represent a deliberately placed zero, for example,
and those where either the data is not recorded in the system or a
NULL has been explicitly entered. As an illustration of this semantic
difference, consider a system that tracks payments. If a product has
a NULL price, that does not mean the product is free; instead, a
NULL price indicates that the amount is not known or perhaps has
not yet been determined.
NOTE
There is a good deal of differentiation between the database platforms
in terms of how they handle NULL values. This leads to some major
porting issues between those platforms relating to NULLs. For example,
an empty string (i.e., a NULL string) is inserted as a NULL value on
Oracle. All the other databases covered in this book permit the insertion
of an empty string into VARCHAR and CHAR columns.
When columns that contain NULL values are listed in the GROUP
BY clause of a query, the query output contains a single row for
NULL values. In essence, the ANSI/ISO standard considers all
NULLs found to be in a single group.
Views (rule 6)
A view is a virtual table that does not exist as a physical repository
of data, but is instead constructed on the fly from a SELECT
statement whenever that view is queried. Views enable you to
construct different representations of the same source data for a
variety of audiences without having to alter the way in which the
data is stored.
NOTE
Some vendors support database objects called materialized views .
Don’t let the similarity of terms confuse you; materialized views are not
governed by the same rules as ANSI/ISO standard views.
Set operations (rules 7 and 12)
Other database manipulation languages, such as the venerable
Xbase, perform their data operations quite differently from SQL.
These languages require you to tell the program exactly how to treat
the data, one record at a time. Since the program iterates down
through a list of records, performing its logic on one record after
another, this style of programming is frequently called r ow,
processing or procedural programming .
In contrast, SQL programs operate on logical sets of data. Set theory
is applied in almost all SQL statements, including SELECT , INSERT ,
UPDATE , and DELETE statements. In effect, data is selected from a
set called a “table.” Unlike the row-processing style, set processing
allows a programmer to tell the database simply what is required,
not how each individual piece of data should be handled. Sometimes
set processing is referred to as declarative processing , since a
developer declares only what data is wanted (as in declaration,
“Return all employees in the southern region who earn more than
$70,000 per year”) rather than describing the exact steps used to
retrieve or manipulate the data.
NOTE
Set theory was the brainchild of mathematician Georg Cantor, who
developed it at the end of the nineteenth century. At the time, set
theory (and Cantor’s theory of the infinite) was quite controversial.
Today, set theory is such a common part of life that it is learned in
elementary school. Things like card catalogs, the Dewey Decimal
System, and alphabetized phone books are all simple and common
examples of applied set theory.
Relational databases use relational algebra and tuple relational calculus
to mathematically model the data in a given database and queries
acting upon that data. These theories were also introduced by E. F.
Codd along with his twelve rules for relational databases.
Examples of set theory in conjunction with relational databases are
detailed in the following section.
Codd’s Rules in Action: Simple SELECT
Examples
Up to this point, this chapter has focused on the individual aspects
of a relational database platform as defined by Codd and
implemented under ANSI/ISO SQL. This following section presents a
high-level overview of the most important SQL statement, SELECT ,
and some of its most salient points—namely, the relational
operations known as projections , selections , and joins :
Projection
Retrieves specific columns of data
Selection
Retrieves specific rows of data
Join
Returns columns and rows from two or more tables in a single
result set
Whereas the first query retrieved all authors, the result of this
second query is a much smaller set of records:
NOTE
Different vendors allow you to join varying numbers of tables in a single
join operation. For example, older database platforms topped out at 256
tables join operations in a given query. Today, most database platforms
are limited only by available system resources.
However, keep in mind that your database engine will consume more
system resources and incur more latency the more tables you join in a
single query. For example, a single SELECT statement joining 12 tables
will have to consider up to 28,158,588,057,600 possible join orders.
Consequently, many experienced SQL developers try to limit their
SELECT statements to no more than 6 joins. When a SELECT statement
exceeds 6 joins, they usually break the query into multiple distinct
queries for faster processing.
-- ANSI style
SELECT a.au_fname, a.au_lname, t.title_id
FROM authors AS a
JOIN titleauthor AS t ON a.au_id = t.au_id
WHERE a.state <> 'CA';
-- Theta style
SELECT a.au_fname, a.au_lname, t.title_id
FROM authors AS a,
titleauthor AS t
WHERE a.au_id = t.au_id
AND a.state <> 'CA';
Sampling
SQL3 adds the TABLESAMPLE clause to the FROM clause. This is
useful for statistical queries on large databases, such as a data
warehouse.
Part 2, SQL/Foundation
Includes the Core, an augmentation of the SQL99 Core. This is
the largest and most important part of the standard.
Table 1-1.
SQL3 statement classes
Those who work with SQL regularly should become familiar with
both the old (SQL92) and the new (SQL3 and later) statement
classes, since both nomenclatures are still used to refer to SQL
features and statements.
SQL Dialects
The constantly evolving nature of the SQL standard has given rise to
a number of SQL dialects among the various vendors and platforms.
These dialects commonly evolve because a given database vendor’s
user community requires capabilities in the database before the
ANSI/ISO committee creates an applicable standard. Occasionally,
though, the academic or research communities introduce a new
feature in response to pressures from competing technologies. For
example, many database vendors are augmenting their current
programmatic offerings with either JSON or . In the future,
developers will use these programming languages in concert with
SQL to build SQL programs.
Many of these dialects include conditional processing capabilities
(such as those that control processing through IF . . . THEN
statements), control-of-flow functions (such as WHILE loops),
variables, and error-handling capabilities. Because ANSI/ISO had not
yet developed a standard for these important features at the time
users began to demand them, RDBMS developers and vendors
created their own commands and syntax. In fact, some of the
earliest vendors from the 1980s have variances in the most
elementary commands, such as SELECT , because their
implementations predate the standards. When attempting to create
SQL code that is interoperable across database platforms, keep in
mind that your mileage may vary.
Some of these dialects introduced procedural commands to support
the functionality of a more complete programming language. For
example, these procedural implementations contain error-handling
commands, control-of-flow language, conditional commands,
variable-handling commands, support for arrays, and many other
extensions. Although these are technically divergent procedural
implementations, they are called dialects here. The SQL/PSM
(Persistent Stored Module) package provides many features
associated with programming stored procedures and incorporates
many of the extensions offered by these dialects.
Some popular dialects of SQL include:
PL/pgSQL
SQL dialect and extensions implemented in PostgreSQL. The
acronym stands for Procedural Language/PostgreSQL.
PL/SQL
Found in Oracle. PL/SQL stands for Procedural Language/SQL
and contains many similarities to the language Ada.
SQL/PSM
MySQL and MariaDB implement the SQL/Persistent Stored
Module of the Core SQL standard. MariaDB also supports PL/SQL.
Transact-SQL
Used by both Microsoft SQL Server and Sybase Adaptive Server,
now owned by SAP. As Microsoft and SAP/Sybase have moved
away from the common platform they shared early in the 1990s,
their implementations of Transact-SQL have also diverged widely.
But the most basic commands are still very similar.
Oracle
Oracle is a leading RDBMS in the commercial sector. Oracle was
the first commercially available SQL database platform, released
in the summer of 1979, running on Vax computers as Oracle v2.
Since that time, Oracle has grown to run on a multitude of
operating systems and hardware platforms. Its scalable, reliable
architecture has made it the platform of choice for many users.
In this edition, we cover Oracle Database 19c .
PostgreSQL
PostgreSQL is the most feature-rich open source database
platform available. For the last several years, PostgreSQL has
seen a steep rise in popularity with a strongly upward trend.
PostgreSQL is best known for its excellent support for ANSI/ISO
standards and robust transaction processing capabilities, as well
as its rich data type and database object support. In addition to
its full set of features, PostgreSQL runs on a wide variety of
operating systems and hardware platforms. This book covers
PostgreSQL 13.
SQL Server
Microsoft SQL Server is a popular RDBMS that runs on the
Windows and Linux operating systems. Its features include ease
of use, an all-inclusive feature set covering OLTP and analytic
workloads, low cost, and high performance. This book covers
Microsoft SQL Server 2019.
Categories of Syntax
To begin to use SQL, readers should understand how statements are
written. SQL syntax falls into four main categories. Each category is
introduced in the following list and then explained in further detail in
the sections that follow:
Identifiers
Describe a user- or system-supplied name for a database object,
such as a database, a table, a constraint on a table, a column in
a table, a view, etc.
Literals
Describe a user- or system-supplied string or value that is not
otherwise an identifier or a keyword. Literals may be strings like
“hello” , numbers like 1234 , dates like “Jan 01, 2002”, or
Boolean values like TRUE .
Operators
Are symbols specifying an action to be performed on one or more
expressions, most often in DELETE , INSERT , SELECT , or
UPDATE statements. Operators are also used frequently in the
creation of database objects.
The room shown in fig. 96 gives a fair idea of the appearance of the
guest-room with its two bays or recesses, the tokonoma and chigai-
dana,—one of which, the tokonoma, is a clear recess, in which
usually hangs a picture; and in the other is a small closet and shelf,
and an additional shelf above, closed by sliding doors. The sketch
was taken from the adjoining room, the fusuma between the two
having been removed. The grooves for the fusuma may be seen in
the floor and in the kamoi overhead. The farther recess is called the
tokonoma, which means literally, “bed-space.” This recess, or at least
its raised platform, is supposed to have been anciently used for the
bed-place.15
How different has been the treatment of similar features in the finish
of American rooms! Everywhere in our apartments, halls, school-
houses, inside and out, a monotonous bi-lateral symmetry is
elaborated to the minutest particular, even to bracket and notch in
pairs. The fireplace is in the middle of the room, the mantel, and all
the work about this opening, duplicated with painful accuracy on
each side of a median line; every ornament on the mantel-shelf is in
pairs, and these are arranged in the same way; a single object, like a
French clock, is adjusted in the dead centre of this shelf, so that each
half of the mantel shall get its half of a clock; a pair of andirons
below, and portraits of ancestral progenitors on each side above keep
up this intolerable monotony; and opposite, two windows with draped
curtains parted right and left, and a symmetrical table or cabinet
between the two, are in rigid adherence to this senseless scheme.
And outside the monotony is still more dreadful, even to the fences,
carriage-way and flower-beds; indeed, false windows are introduced
in adherence to this inane persistency in traditional methods. Within
ten years some progress has been made among the better class of
American houses in breaking away from this false and tiresome idea,
and our houses look all the prettier for these changes. In decoration,
as well, we have made great strides in the same direction, thanks to
the influence of Japanese methods.
[pg 137]
While the general description just given of the tokonoma and chigai-
dana may be regarded as typical of the prevailing features of these
recesses, nevertheless their forms and peculiarities are infinitely
varied. It is indeed rare to find the arrangement of the shelves and
cupboards in the chigai-dana alike in any two houses, as will be seen
by a study of the figures which are to follow. Usually these two
recesses are side by side, and run at right angles with the verandah,
the tokonoma almost invariably coming next to the verandah.
Sometimes, however, these two recesses may stand at right angles to
one another, coming in a corner of the room away from the
verandah. The tokonoma may be seen also without its companion
recess, and sometimes it may occupy an entire side of the room, in
which case it not infrequently accommodates a set of two or three
pictures. When these recesses come side by side, it is usual to have
an entire mat in front of each recess. The guest of honor is seated on
the mat in front of the tokonoma, while the guest next in honor
occupies a mat in front of the chigai-dana.
In Fig. 123 the tokonoma occupies almost the entire side of the
room, the chigai-dana being reduced to an angular cupboard placed
in the corner and a small hooded partition hanging down from above;
the small window near by, with bamboo lattice, opened into another
room beyond. A tokonoma of this kind is available for the display of
sets of three or four pictures. This room was in the house of a former
Daimio.
[pg 144]
In the next figure (fig. 124) we have the sketch of a small room with
the tokonoma facing the verandah, and with no companion recess.
The little window near the floor opened into the tokonoma, which
extended behind the partition as far as the upright beam. The post
which formed one side of the tokonoma was a rough and irregular-
shaped stick. The treatment of cutting away a larger portion of it,
though hardly constructive, yet added a quaint effect to the room;
while the cross-beam of the tokonoma. usually a square and finished
[pg 145] beam, in this case was in a natural state, the bark only
being removed.
The next figure (fig. 126) is that of a room in the second story of the
house of a famous potter in Kioto. This room [pg 146] was
remarkable for the purity of its finish. The toko-bashira consisted of
an unusually twisted stick of some kind of hard wood, the bark
having been removed, exposing a surface of singular smoothness.
The hooded partition over the chigai-dana had for its lower border a
rich dark-brown bamboo; the vertical piece forming the other side of
the chigai-dana was a black post hewn in an octagonal shape, with
curious irregular crosscuts on the faces. The sliding doors closing the
shelf in this recess were covered with gold paper. The hikite consisted
of sections of bamboo let in to the surface. The plaster of both
recesses was a rich, warm, umber color. The ceiling consisted [pg
147] of large square panels of old cedar richly grained. This room
was comparatively modern, having been built in 1868.
The figures of interiors thus far given present some idea of the
infinite variety of design seen in the two recesses which characterize
the best room in the house. The typical form having been shown in
fig. 96, it will be seen how far these bays may vary in form and
structure while still possessing the distinguishing features of the
tokonoma and chigai-dana. In the first recess hangs the ever present
scroll, upon which may be a picture; or it may present a number of
Chinese characters which convey some moral precept, or lines from
some classical poem. On its floor rests the vase for flowers, a figure
in pottery, an incense burner, a fragment of quartz, or other object,
these being often supported by a lacquer stand. In the chigai-dana
convenient shelves and closets are arranged in a variety of ways, to
be used for a variety of purposes.
[pg 149]
In houses of two stories greater latitude is shown in the arrangement
of these recesses. They may come opposite the balcony, and the
chigai-dana may have in its back wall an opening either circular,
crescent-shaped, or of some other form, from which a pleasing view
is obtained either of the garden below or some distant range beyond.
Thus far we have examined the room which would parallel our
drawing-room or parlor; the other rooms vary from this in being
smaller, and having, of course, no recesses such as have been
described. By an examination of the plans given in the first part of
this chapter, it will be seen how very simple many of the rooms are,—
sometimes having a recess for a case of drawers or shelves; a closet,
possibly, but nothing else to break the rectangular outline, which may
be bounded on all sides by the sliding fusuma, or have one or more
permanent partitions.
In brief, the party comes about by the host inviting a company of four
to attend the tea-ceremony, and in their presence making the tea in a
bowl after certain prescribed forms, and offering it to the guests. To
be more explicit as to the mode of conducting this ceremony,—the
tea is first prepared by grinding it to a fine, almost impalpable,
powder. This may be done by a servant before the assemblage of the
guests, or may be ordered ground from a tea shop; indeed, the host
may grind it himself. This material, always freshly ground for each
party, is usually kept in a little earthen jar, having an ivory cover,—the
[pg 150] well-known cha-ire of the collector. Lacquer-boxes may also
be used for this purpose. The principal utensils used in the ceremony
consist of a furo, or fire-pot, made of pottery (or use may be made of
a depression in the floor partially filled with ashes, in which the
charcoal may be placed); an iron kettle to boil the water in; a
bamboo dipper of the most delicate construction, to dip out the
water; a wide-mouthed jar, from which to replenish the water in the
kettle; a bowl, in which the tea is made; a bamboo spoon, to dip out
the powdered tea; a bamboo stirrer, not unlike certain forms of egg-
beaters, by which the tea is briskly stirred after the hot water has
been added; a square silk cloth, with which to wipe the jar and spoon
properly; a little rest for the tea-kettle cover, made of pottery or
bronze or section of bamboo; a shallow vessel, in which the rinsings
of the tea-bowl are poured after washing; a brush, consisting of three
feathers of the eagle or some other large bird, to dust the edge of
the fire-vessel; and finally a shallow basket, in which is not only
charcoal to replenish the fire, but a pair of metal rods or hibashi to
handle the coal, two interrupted metal rings by which the kettle is
lifted off the fire, a circular mat upon which the kettle is placed, and a
small box containing incense, or bits of wood that give out a peculiar
fragrance when burned. With the exception of the fire-vessel and an
iron kettle, all these utensils have to be brought in by the host with
great formality and in a certain sequence, and placed with great
precision upon the mats after the prescribed rules of certain schools.
In the making of the tea, the utensils are used in a most exact and
formal manner.
The making of the tea, watched by one knowing nothing about the
ceremony, seems as grotesque a performance as one can well
imagine. Many of the forms connected with it seem uselessly absurd;
and yet having taken many lessons in the art of tea-making, I found
that with few exceptions it was natural [pg 151] and easy; and the
guests assembled on such an occasion, though at first sight
appearing stiff, are always perfectly at their ease. The proper placing
of the utensils, and the sequence in handling them and making the
tea are all natural and easy movements, as I have said. The light
wiping of the tea-jar, and the washing of the bowl and its wiping with
so many peripheral jerks, the dropping of the stirrer against the side
of the bowl with a click in rinsing, and a few of the other usual
movements are certainly grotesquely formal enough; but I question
whether the etiquette of a ceremonious dinner-party at home, with
the decorum observed in the proper use of each utensil, does not
strike a Japanese as equally odd and incomprehensible when
experienced by him for the first time.
This very brief and imperfect allusion has been made in order to
explain, that so highly do the Japanese regard this ceremony that
little isolated houses are specially constructed for the express
purpose of entertaining tea-parties. If no house is allotted for the
purpose, then a special room is fitted for it. Many books are devoted
to the exposition of the different schools of tea-ceremonies,
illustrated with diagrams showing the various ways of placing the
utensils, plans of the tea-rooms, and all the details involved in the
observances.
bookless, pictureless,
Save the inevitable sampler hung
Over the fireplace; or a mourning-piece,—
A green-haired woman, peony-cheeked, beneath
Impossible willows; the wide-throated hearth
Bristling with faded pine-boughs, half concealing
The piled-up rubbish at the chimney's back.
[pg 153]
Fig. 130.—Tea-room in Nan-en-ji temple, Kioto.
[pg 155]
In some houses there is a special place or room adjoining the tea-
room, in which the tea-utensils are kept properly arranged, and from
which they are brought when tea is made, and to which they are
afterwards returned with great formality. Fig. 133 represents one of
these rooms in a house in Imado, Tokio. In this room the same
simplicity of finish was seen. It was furnished [pg 156] with shelves,
a little closet to contain the utensils, and a depressed area in the
floor, having for its bottom a bamboo grating through which the
water ran when emptied into it. Resting upon this bamboo grating
were a huge pottery-vessel for water and a common hand-basin of
copper. The floor was of polished wood. At the farther end was the
entrance, by means of a low door, closed by fusuma.
Fig. 133.—Kitchen for tea-utensils.
Fig. 134.—Tea-room in Imado, Tokio.
In fig. 134 is given the view of a room in a Tokio house that was
extremely ornate in its finish. The owner of the house had built it
some thirty years before, and had intended carrying out Chinese
ideas of design and furnishing. Whether he had got his ideas from
books, or had evolved them from his inner consciousness, I do not
know; certain it is, that although he had worked into its structure a
number of features actually [pg 157] brought from China, I must say
that in my limited observations in that country I saw nothing
approaching such an interior or building. The effect of the room was
certainly charming, and the most elaborate finish with expensive
woods had been employed in its construction. It seemed altogether
too ornamental for the tea-ceremonies to suit the Japanese taste.
The ceiling was particularly unique; for running diagonally across it
from one corner to the other was a stout bamboo in two curves, and
upon this bamboo was engraved a Chinese poem. The ceiling on one
side of the bamboo was finished in large square panels of an
elaborately-grained wood; on the other side were small panels of
cedar. Exotic woods, palms, bamboo, and red-pine were used for