Learning SQL 1st Edition Alan Beaulieu download
Learning SQL 1st Edition Alan Beaulieu download
download
https://ebookfinal.com/download/learning-sql-1st-edition-alan-
beaulieu/
https://ebookfinal.com/download/learning-sql-2nd-edition-alan-
beaulieu/
https://ebookfinal.com/download/impact-techniques-for-therapists-1st-
edition-danie-beaulieu/
https://ebookfinal.com/download/improving-professional-learning-
twelve-strategies-to-enhance-performance-1st-edition-alan-b-knox/
Healthy SQL A Comprehensive Guide to Healthy SQL Server
Performance 1st Edition Robert Pearl
https://ebookfinal.com/download/healthy-sql-a-comprehensive-guide-to-
healthy-sql-server-performance-1st-edition-robert-pearl/
https://ebookfinal.com/download/simply-sql-1st-edition-rudy-limeback/
https://ebookfinal.com/download/netezza-sql-1st-edition-tom-coffing/
https://ebookfinal.com/download/sql-quickstart-guide-the-simplified-
beginner-s-guide-to-sql-clydebank-technology/
https://ebookfinal.com/download/sql-and-relational-theory-how-to-
write-accurate-sql-code-3ed-edition-date/
Learning SQL 1st Edition Alan Beaulieu Digital Instant
Download
Author(s): Alan Beaulieu
ISBN(s): 9780596007270, 0596007272
Edition: 1
File Details: PDF, 1.79 MB
Year: 2005
Language: english
Learning SQL
By Alan Beaulieu
...............................................
Publisher: O'Reilly
Pub Date: August 2005
ISBN: 0-596-00727-2
Pages: 306
SQL (Structured Query Language) is a standard programming language for generating, manipulating,
and retrieving information from a relational database. If you're working with a relational database--
whether you're writing applications, performing administrative tasks, or generating reports--you need to
know how to interact with your data. Even if you are using a tool that generates SQL for you, such as a
reporting tool, there may still be cases where you need to bypass the automatic generation feature and
write your own SQL statements.
To help you attain this fundamental SQL knowledge, look to Learning SQL, an introductory guide to SQL,
designed primarily for developers just cutting their teeth on the language.
Learning SQL moves you quickly through the basics and then on to some of the more commonly used
advanced features. Among the topics discussed:
SQL Data Statements--those used to create, manipulate, and retrieve data stored in your
database; example statements include select, update, insert, and delete
SQL Schema Statements--those used to create database objects, such as tables, indexes, and
constraints
Best of all, Learning SQL talks to you in a real-world manner, discussing various platform differences
that you're likely to encounter and offering a series of chapter exercises that walk you through the
learning process. Whenever possible, the book sticks to the features included in the ANSI SQL
standards. This means you'll be able to apply what you learn to any of several different databases; the
book covers MySQL, Microsoft SQL Server, and Oracle Database, but the features and syntax should
apply just as well (perhaps with some tweaking) to IBM DB2, Sybase Adaptive Server, and PostgreSQL.
Put the power and flexibility of SQL to work. With Learning SQL you can master this important skill and
know that the SQL statements you write are indeed correct.
Learning SQL
By Alan Beaulieu
...............................................
Publisher: O'Reilly
Pub Date: August 2005
ISBN: 0-596-00727-2
Pages: 306
Copyright
Preface
Why Learn SQL?
Why Use This Book to Do It?
Structure of This Book
Conventions Used in This Book
How to Contact Us
Using Code Examples
Safari Enabled
Acknowledgments
Chapter 1. A Little Background
Section 1.1. Introduction to Databases
Section 1.2. What Is SQL?
Section 1.3. What Is MySQL?
Section 1.4. What's in Store
Chapter 2. Creating and Populating a Database
Section 2.1. Creating a MySQL Database
Section 2.2. Using the mysql Command-Line Tool
Section 2.3. MySQL Data Types
Section 2.4. Table Creation
Section 2.5. Populating and Modifying Tables
Section 2.6. When Good Statements Go Bad
Section 2.7. The Bank Schema
Chapter 3. Query Primer
Section 3.1. Query Mechanics
Section 3.2. Query Clauses
Section 3.3. The select Clause
Section 3.4. The from Clause
Section 3.5. The where Clause
Section 3.6. The group by and having Clauses
Section 3.7. The order by Clause
Section 3.8. Exercises
Chapter 4. Filtering
Section 4.1. Condition Evaluation
Section 4.2. Building a Condition
Section 4.3. Condition Types
Section 4.4. NULL: That Four-Letter Word
Section 4.5. Exercises
Chapter 5. Querying Multiple Tables
Section 5.1. What Is a Join?
Section 5.2. Joining Three or More Tables
Section 5.3. Self-Joins
Section 5.4. Equi-Joins Versus Non-Equi-Joins
Section 5.5. Join Conditions Versus Filter Conditions
Section 5.6. Exercises
Chapter 6. Working with Sets
Section 6.1. Set Theory Primer
Section 6.2. Set Theory in Practice
Section 6.3. Set Operators
Section 6.4. Set Operation Rules
Section 6.5. Exercises
Chapter 7. Data Generation, Conversion, and Manipulation
Section 7.1. Working with String Data
Section 7.2. Working with Numeric Data
Section 7.3. Working with Temporal Data
Section 7.4. Conversion Functions
Section 7.5. Exercises
Chapter 8. Grouping and Aggregates
Section 8.1. Grouping Concepts
Section 8.2. Aggregate Functions
Section 8.3. Generating Groups
Section 8.4. Group Filter Conditions
Section 8.5. Exercises
Section 8.6. 8-4 (Extra Credit)
Chapter 9. Subqueries
Section 9.1. What Is a Subquery?
Section 9.2. Subquery Types
Section 9.3. Noncorrelated Subqueries
Section 9.4. Correlated Subqueries
Section 9.5. When to Use Subqueries
Section 9.6. Subquery Wrap-up
Section 9.7. Exercises
Chapter 10. Joins Revisited
Section 10.1. Outer Joins
Section 10.2. Cross Joins
Section 10.3. Natural Joins
Section 10.4. Exercises
Chapter 11. Conditional Logic
Section 11.1. What Is Conditional Logic?
Section 11.2. The Case Expression
Section 11.3. Case Expression Examples
Section 11.4. Exercises
Chapter 12. Transactions
Section 12.1. Multiuser Databases
Section 12.2. What Is a Transaction?
Chapter 13. Indexes and Constraints
Section 13.1. Indexes
Section 13.2. Constraints
Appendix A. ER Diagram for Example Database
Appendix B. MySQL Extensions to the SQL Language
Section B.1. Select Extensions
Section B.2. Combination Insert/Update Statements
Section B.3. Ordered Updates and Deletes
Section B.4. Multitable Updates and Deletes
Appendix C. Solutions to Exercises
Section C.1. Chapter 3
Section C.2. Chapter 4
Section C.3. Chapter 5
Section C.4. Chapter 6
Section C.5. Chapter 7
Section C.6. Chapter 8
Section C.7. 8-4 (Extra Credit)
Section C.8. Chapter 9
Section C.9. Chapter 10
Section C.10. Chapter 11
Appendix D. Further Resources
Section D.1. Advanced SQL
Section D.2. Database Programming
Section D.3. Database Design
Section D.4. Database Tuning
Section D.5. Database Administration
Section D.6. Report Generation
Colophon
About the Author
Colophon
Index
Learning SQL
by Alan Beaulieu
Published by O'Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O'Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (safari.oreilly.com). For more information, contact our corporate/institutional
sales department: (800) 998-9938 or corporate@oreilly.com.
Printing History:
Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of
O'Reilly Media, Inc. Learning SQL, the image of an Andean marsupial tree frog, and related trade dress
are trademarks of O'Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O'Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions, or for damages resulting from the use of the information
contained herein.
ISBN: 0-596-00727-2
[M]
Preface
Programming languages come and go constantly, and very few languages in use today have roots going
back more than a decade or so. Some examples are Cobol, which is still used quite heavily in mainframe
environments, and C, which is still quite popular for operating system and server development and for
embedded systems. In the database arena, we have SQL, whose roots go all the way back to the 1970s.
SQL is the language for generating, manipulating, and retrieving data from a relational database. One of
the reasons for the popularity of relational databases is that properly designed relational databases can
handle huge amounts of data. When working with large data sets, SQL is akin to one of those snazzy
digital cameras with the high-power zoom lens in that you can use SQL to look at large sets of data, or
you can zoom in on individual rows (or anywhere in between). Other database management systems tend
to break down under heavy loads because their focus is too narrow (the zoom lens is stuck on maximum),
which is why attempts to dethrone relational databases and SQL have largely failed. Therefore, even
though SQL is an old language, it is going to be around for a lot longer and has a bright future in store.
Why Learn SQL?
If you are going to work with a relational database, whether you are writing applications, performing
administrative tasks, or generating reports, you will need to know how to interact with the data in your
database. Even if you are using a tool that generates SQL for you, such as a reporting tool, there may be
times when you need to bypass the automatic generation feature and write your own SQL statements.
Learning SQL has the added benefit of forcing you to confront and understand the data structures used to
store information about your organization. As you become comfortable with the tables in your database,
you may find yourself proposing modifications or additions to your database schema.
Why Use This Book to Do It?
The SQL language is broken into several categories. Statements used to create database objects (tables,
indexes, constraints, etc.) are collectively known as SQL schema statements. The statements used to
create, manipulate, and retrieve the data stored in a database are known as the SQL data statements. If
you are an administrator, you will be using both SQL schema and SQL data statements. If you are a
programmer or report writer, you may only need to use (or be allowed to use) SQL data statements.
While this book demonstrates many of the SQL schema statements, the main focus of this book is on
programming features.
With only a handful of commands, the SQL data statements look deceptively simple. In my opinion, many
of the available SQL books help to foster this notion by only skimming the surface of what is possible with
the language. However, if you are going to work with SQL, it behooves you to understand fully the
capabilities of the language and how different features can be combined to produce powerful results. I feel
that this is the only book that provides detailed coverage of the SQL language without the added benefit
of doubling as a "door stop" (you know, those 1,250-page "complete references" that tend to gather dust
on people's cubicle shelves).
While the examples in this book run on MySQL, Oracle Database, and SQL Server, I had to pick one of
those products to host my sample database and to format the result sets returned by the example
queries. Of the three, I chose MySQL because it is freely obtainable, easy to install, and simple to
administer. For those readers using a different server, I ask that you download and install MySQL and
load the sample database so that you can run the examples and experiment with the data.
Structure of This Book
Chapter 1, A Little Background, explores the history of computerized databases, including the rise of
the relational model and the SQL language.
Chapter 2, Creating and Populating a Database, demonstrates how to create a MySQL database,
create the tables used for the examples in this book, and populate the tables with data.
Chapter 3, Query Primer, introduces the select statement and further demonstrates the most
common clauses (select, from, where).
Chapter 4, Filtering, demonstrates the different types of conditions that can be used in the where
clause of a select, update, or delete statement.
Chapter 5, Querying Multiple Tables, shows how queries can utilize multiple tables via table joins.
Chapter 6, Working with Sets, is all about data sets and how they can interact within queries.
Chapter 7, Data Generation, Conversion, and Manipulation, demonstrates several built-in functions
used for manipulating or converting data.
Chapter 9, Subqueries, introduces the subquery (a personal favorite) and shows how and where
they can be utilized.
Chapter 10, Joins Revisited, further explores the various types of table joins.
Chapter 11, Conditional Logic, explores how conditional logic (i.e., if-then-else) can be utilized in
select, insert, update, and delete statements.
Chapter 12, Transactions, introduces transactions and shows how to use them.
Appendix A, ER Diagram for Example Database, shows the database schema used for all examples in
the book.
Appendix B, MySQL Extensions to the SQL Language, demonstrates some of the interesting non-
ANSI features of MySQL's SQL implementation.
Appendix D, Further Resources, suggests where to turn for more advanced training.
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Used for filenames, directory names, and URLs. Also used for emphasis and to indicate the first use
of a technical term.
Constant width
Used for code examples and to indicate SQL keywords within text.
UPPERCASE
Indicates user input in examples showing an interaction. Also indicates emphasized code elements
to which you should pay particular attention.
Indicates a tip, suggestion, or general note. For example, I use notes to point you
to useful new features in Oracle9i.
Indicates a warning or caution. For example, I'll tell you if a certain SQL clause
might have unintended consequences if not used carefully.
How to Contact Us
Please address comments and questions concerning this book to the publisher:
O'Reilly maintains a web page for this book, which lists errata, examples, and any additional information.
You can access this page at:
http://www.oreilly.com/catalog/learningsql
To comment or ask technical questions about this book, send email to:
bookquestions@oreilly.com
For more information about O'Reilly books, conferences, Resource Centers, and the O'Reilly Network, see
the web site at:
http://www.oreilly.com
Using Code Examples
This book is here to help you get your job done. In general, you may use the code in this book in your
programs and documentation. You do not need to contact us for permission unless you're reproducing a
significant portion of the code. For example, writing a program that uses several chunks of code from this
book does not require permission. Selling or distributing a CD-ROM of examples from O'Reilly books does
require permission. Answering a question by citing this book and quoting example code does not require
permission. Incorporating a significant amount of example code from this book into your product's
documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher,
and ISBN. For example: "Learning SQL by Alan Beaulieu. Copyright 2005 O'Reilly Media, Inc., 0-596-
00727-2."
If you feel your use of code examples falls outside fair use or the permission given above, feel free to
contact us at permissions@oreilly.com.
Safari Enabled
When you see a Safari® Enabled icon on the cover of your favorite technology book, that
means the book is available online through the O'Reilly Network Safari Bookshelf.
Safari offers a solution that's better than e-books. It's a virtual library that lets you easily search
thousands of top tech books, cut and paste code samples, download chapters, and find quick answers
when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.
Acknowledgments
A book is a living thing, and what you now hold in your hands is a far cry from my initial ramblings. The
person most responsible for this metamorphosis is my editor, Jonathan Gennick; thank you for your
assistance in every step of this project, both for your editorial prowess and your expertise with the SQL
language. Next, I would like to acknowledge my three technical reviewers, Peter Gulutzan, Joseph
Molinaro, and Jeff Cox, who challenged me to make this book both technically sound and appropriate for
readers new to SQL. Also, many thanks to the multitude of people at O'Reilly Media who have helped
make this book a reality, including my production editor, Matt Hutchinson; the cover designer, Ellie
Volckhausen; and the illustrator, Rob Romano.
Chapter 1. A Little Background
Before we roll up our sleeves and get to work, it might be beneficial to introduce some basic database
concepts and look at the history of computerized data storage and retrieval.
1.1. Introduction to Databases
A database is nothing more than a set of related information. A telephone book, for example, is a
database of the names, phone numbers, and addresses of all people living in a particular region. While a
telephone book is certainly a ubiquitous and frequently used database, it suffers from the following:
Finding a person's telephone number can be time consuming, especially if the telephone book
contains a large number of entries.
A telephone book is only indexed by last/first names, so finding the names of the people living at a
particular address, while possible in theory, is not a practical use for this database.
From the moment the telephone book is printed, the information becomes less and less accurate as
people move into or out of a region, change their telephone numbers, or move to another location
within the same region.
The same drawbacks attributed to telephone books can also apply to any manual data storage system,
such as patient records stored in a filing cabinet. Because of the cumbersome nature of paper databases,
some of the first computer applications developed were database systems, which are computerized data
storage and retrieval mechanisms. Because a database system stores data electronically rather than on
paper, a database system is able to retrieve data more quickly, index data in multiple ways, and deliver
up-to-the-minute information to its user community.
Early database systems managed data stored on magnetic tapes. Because there were generally far more
tapes than tape readers, technicians were tasked with loading and unloading tapes as specific data was
required. Because the computers of that era had very little memory, multiple requests for the same data
generally required the data to be read from the tape multiple times. While these database systems were a
significant improvement over paper databases, they are a far cry from what is possible with today's
technology. (Modern database systems can manage terabytes of data spread across many fast-access
disk drives, holding tens of gigabytes of that data in high-speed memory, but I'm getting a bit ahead of
myself.)
For the first several decades of computerized database systems, data was stored and represented to
users in various ways. In a hierarchical database system, for example, data is represented as one or more
tree structures. Figure 1-1 shows how data relating to George Blake's and Sue Smith's bank accounts
might be represented via tree structures.
Another common approach, called the network database system, exposes sets of records and sets of links
that define relationships between different records. Figure 1-2 shows how George's and Sue's same
accounts might look in such a system.
2. Follow the link from Sue Smith's customer record to her list of accounts.
3. Traverse the chain of accounts until you find the money market account.
4. Follow the link from the money market record to its list of transactions.
One interesting feature of network database systems is demonstrated by the set of product records on
the far right of Figure 1-2. Notice that each product record (Checking, Savings, etc.) points to a list of
account records that are of that product type. Account records, therefore, can be accessed from multiple
places (both customer records and product records), allowing a network database to act as a multiparent
hierarchy.
Both hierarchical and network database systems are alive and well today, although generally in the
mainframe world. Additionally, hierarchical database systems have enjoyed a rebirth in the directory
services realm, such as Microsoft's Active Directory and Netscape's Directory Server, as well as with
Extensible Markup Language (XML). Beginning in the 1970s, however, a new way of representing data
began to take root, one that was more rigorous yet easy to understand and implement.
Discovering Diverse Content Through
Random Scribd Documents
This resolution was adopted without debate, and unanimously, by
both houses on June 22, and approved by the President on June 26,
1906.
CHAPTER XXXVIII.
THE AMERICAN-JEWISH COMMITTEE. EDUCATIONAL
INSTITUTIONS AND FEDERATIONS.
Formation of the American Jewish Committee—Its first fifteen members and its
membership in 1911—The experimental Kehillah organizations—The re-
organized Jewish Theological Seminary—Faculty of the Hebrew Union College
—The Dropsie College of Hebrew and Cognate Learning—The Rabbi Joseph
Jacob School—Other Orthodox “Yeshibot”—Talmud Torahs and “Chedarim”—
Hebrew Institutes—They become more Jewish because other agencies now do
the work of Americanizing the immigrant—Technical Schools—Young Men’s
and Young Women’s Hebrew Associations—Federations of various kinds.
The Rev. Jacob Raphael Cohen was the first regular minister of
the Montreal congregation of whom there remains any record. He
came there in 1778 and remained until 1782, when he went to
Philadelphia, where he became rabbi of Congregation Mickweh
Israel. The president or parnas of the Montreal congregation in 1775
was Jacob Salesby (or Salisbury) Franks, a member of the family
whose other branch played an important part in Philadelphia in the
period of the Revolution. Abraham Franks (1721–97) supported the
British in repelling the American invasion, while his son-in-law, Levy
Solomons, who later became parnas of the Montreal congregation,
was commanded by the invading American general, Montgomery, to
act as purveyor to the hospitals for the American troops. But after
the death of General Montgomery and the retreat of the American
forces from Canada, Solomons, who was never paid for the services
he rendered to the invaders, was exposed to the resentment of the
British, as one suspected of sympathy for the revolting colonists. He
and his family were expelled from Montreal by General Burgoyne,
but eventually was permitted to return.
CHAPTER XL.
JEWS IN SOUTH AMERICA, MEXICO AND CUBA.
The first “minyan” in Buenos Ayres, Argentine, in 1861—Estimate of the Jewish
population in Argentine—Occupations and economic condition of the various
groups—Kosher meat and temporary synagogues as indications of the
religious conditions—Communities in twenty-six other cities—The Agricultural
Colonies—Brazil—The rumor that General Floriano Peixotto, the second
president of the new Republic, was of Jewish origin—Communities in several
cities—The Colony Philippson—Jews in Montevido, Uruguay—Other South
American Republics—Isidor Borowski, who fought under Bolivar—Panama—
Moroccan Jews are liked by Peru Indians—About ten thousand Jews in Mexico
—Slowly increasing number in Cuba, where Jews help to spread the American
influence.
The largest share of attention was, however, paid in the last two
decades to that part of the Jewish population of Argentine which has
settled in the agricultural colonies established by the I. C. A. As early
as 1889 independent attempts had been made by Jewish immigrants
from Russia to establish colonies in Argentine, but it was not done
on a well-ordered plan, and later these colonies and colonists were
absorbed by the Jewish Colonization Association. The oldest and
most successful colony, Moiseville, founded by Russian immigrants in
1890, before the establishment of the I. C. A. was re-organized by
that association in 1891. Mauricio, in the province of Buenos Ayres,
was established about the same time, and the large group of
colonies in the province of Entre Rios, which is collectively called
Clara (after the Baroness de Hirsch), was founded in 1894. Despite
the friction which caused many colonists at considerable expense, to
leave the places where they were settled, and despite the prejudice
which was aroused against the entire colonization scheme by these
seemingly interminable quarrels, the agricultural colonies in
Argentine, as a whole, are successful and their future is bright. The
colonists are fast paying off their debts to the association which
assisted them to settle there, and many of them are even chafing
under the limitations which prevent them from paying off more
rapidly. The centers of Jewish population, both agricultural and—
indirectly—urban, which were thus artificially created by the
munificence of Baron de Hirsch, have become healthy and natural,
and are now attracting independent immigration. There are now, as
stated above, nearly 20,000 souls in the colonies, but more than a
fourth are described as non-colonists. There are 44 schools with
more than 3,000 pupils in the colonies, and the statistical tables
from year to year show a slow and solid progress, which augurs well
for the future of the Jews in Argentine.
There were, as far as known, but very few Jews in modern Brazil,
even under the humane and scholarly Emperor Dom Pedro II.
(1825–91), who was well versed in Hebrew, and maintained friendly
relations with several Jewish scholars in Europe. The immense
country attracted but few Jews after the Emperor was deposed and
a republican form of government instituted in 1889. There were
some rumors at that time that General Floriano Peixotto, one of the
leaders of the revolution, who was the first Vice-President and the
second President (1891–94) of the new republic, was of Jewish
origin. But like the statements about the Jewish ancestry of
Christopher Columbus and many other notables, they could never be
verified, and there is not available sufficient genealogical material in
either case to prove or disprove assertions of that nature.
The chief interest of the Jewish world in the Jews of Brazil is,
however, concentrated on the agricultural colony, Philippson, in the
state of Rio Grande, where there are now settled about 400 Russian
Jews, mostly from Bessarabia. It was founded by the I. C. A. about
six years ago, and is now under the direction of M. Leibowitz, one of
its former oldest employees in Argentine. The colony is in a
flourishing condition, and it is being constantly enlarged, while new
settlements are projected in the same part of the country. Here, too,
like in Argentine, the colony attracts some Jewish immigration, and it
was also the cause of the establishment of small Jewish settlements
in the nearby towns of Pinhal, Santa Maria, Cruz Alta, etc. The
number of Jews in Brazil is now estimated at 3,000.
While the social and political success of the Jews in a country are
usually taken as an indication of its liberalism and the equality of its
citizens, regardless of their creed, the contribution of Jews to its
intellectual and artistic achievements is the best proof that this
equality brings its own reward for the general good. We have seen in
the preceding chapters how the Jews of the United States assisted in
the material development of the country, how they participated in
the battles for its independence and for its preservation, and how
they are now doing their share of the country’s useful work as
working men, as business men, as professional men, etc., some of
them having occupied before, and others occupying now, prominent
positions in various walks of life. It remains now to cite several
instances of Jews who attained distinction in the noble callings of the
artist and the scientist, reflecting glory on their professions, as well
as on the country of their birth or adoption.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com