SQL-TOC Ch1 PDF
SQL-TOC Ch1 PDF
Contents
1 Introducing SQL
What is SQL?
7
8
Making SQL queries 10
Installing MySQL on Windows 12
Installing MySQL on Linux 14
Installing an ODBC driver 16
Using Microsoft Query tool 18
Summary 20
2 Getting started
Introducing databases
21
22
Exploring databases 23
Creating a database 24
Deleting a database 26
Running SQL scripts 28
Summary 30
Index 187
Foreword
The creation of this book has provided me, Mike McGrath, a welcome opportunity to update
my previous books on SQL programming with the latest techniques. All examples I have
given in this book demonstrate SQL features using the current MySQL Relational Database
Management System that is supported on both Windows and Linux operating systems.
Additionally, in order to identify each source code file described in the steps a colored icon and
file name appears in the margin alongside the steps:
SQL
query.sql
l 2 Find “SQL in easy steps, 3rd Edition” in the “Source Code” list, then click on the
hyperlink entitled “All Code Examples” to download the archive
l 3 Now extract the archive contents to any convenient location on your computer
I sincerely hope you enjoy discovering the powerful exciting possibilities of SQL and have as
much fun with it as I did in writing this book.
Mike McGrath
1 Introducing SQL
8 What is SQL?
Welcome to the exciting
10 Making MySQL queries
world of the Structured
12 Installing MySQL on Windows
Query Language (SQL).
14 Installing SQL on Linux
This chapter describes how
16 Installing an ODBC driver
to install free SQL database
18 Using Microsoft Query tool
servers on your system.
20 Summary
Introducing SQL
What is SQL?
The Structured Query Language (SQL) is a language designed
specifically for communicating with databases. Today SQL is the
industry-wide standard language used by most database systems.
SQL
Databases allow collections of data to be stored in an organized
manner – in the same way that data can be stored in an organized
way inside files within a filing cabinet. Most modern DataBase
Management Systems (DBMSs) store data in related tables, so
A programming are called Relational DBMS (RDBMS). The data stored inside
language (pronounced databases can be examined and manipulated by SQL commands.
either “S-Q-L” or
“sequel”) designed to SQL commands are known as “queries” and utilize special
manage database data. keywords that can be used both to add data to a database, or
extract details of data contained within a database. There are not
many keywords so SQL is simple to understand but, despite
its apparent simplicity, is a powerful language. Clever use of its
language components enable complex sophisticated database
operations to be performed.
The model for the basis of SQL was defined back in 1970 by
Dr. E. F. Todd, a researcher for IBM, in a paper entitled
“A Relational Model of Data for Large Shared Data Banks”.
This article generated a great deal of interest in the feasibility of
producing a practical commercial application of such a system.
IBM really began to develop these ideas in 1974 when they
started the System/R project which eventually created the
Structured English Query Language (SEQUEL). This was
rewritten in 1976 to include multi-table and multi-user features
and was renamed SQL in 1978. During this time other software
companies had begun working on database systems based upon
the SQL model. Most notable of these were Oracle, Sybase
and Ingres (from the University of California’s Berkeley Ingres
project). The first to be released commercially was Oracle in 1979.
IBM released improved database products named SQL/DS in
1982 and DB2 in 1983.
Modern versions of Oracle, Sybase, Ingres and DB2 DBMS are
available today and are in widespread use around the world.
…cont’d
Standardization of SQL
In order to clarify the precise nature of SQL, so it could be
implemented universally, each aspect of the language was defined
in 1989 by the American National Standards Institute (ANSI)
in a standard specification known as SQL-89. This was expanded
three years later with publication of the SQL-92 specification
by a joint committee of ANSI and the International Standards “ISO” is not an acronym
Organization (ISO). A third standard specification, SQL-99, was but is derived from
introduced in 1999 to address issues of advanced SQL syntax the Greek word “isos”
and has been subsequently updated with the SQL:2008 standard. meaning equal – as in
“isometric”.
Some DBMS vendors have added proprietary features to the
ANSI-defined SQL standard. These extended versions even have
their own names, such as PL-SQL and Transact-SQL.
The examples given in this book mostly use standard ANSI-SQL
so they can be applied to any DBMS.
9
• that
Directly input through an integral SQL-client application
is part of the DBMS package – this is the most
straightforward method and is used in this book to
demonstrate SQL features
• method
Input through a third-party SQL-client application – this
communicates with the database via an intermediate
Learning standard ANSI-
software “driver”. On Windows systems these are typically SQL enables you to
Open DataBase Connectivity (ODBC) data source drivers interact with every major
• communicate
database that exists.
From a script – often found on web servers to dynamically
with a database using a scripting language such
as PERL or PHP
• programmers
From an Integrated Development Environment (IDE) –
using IDEs, such as Microsoft Visual Basic, can
build programs that incorporate SQL queries to a database
The next two pages outline how to execute SQL queries using a
variety of popular software.
Introducing SQL
Oracle®
The Oracle DBMS is popular and widely used in commerce.
Oracle Database Express Edition (Oracle Database XE) is a free
entry-level, small-footprint database that is simple to administer.
SQL queries can be executed from its SQL> command prompt.
IBM® DB2®
11
The DB2 DBMS is a powerful multi-platform database system.
DB2-Express-C is another free full function DB2 data server.
SQL queries can be executed from its db2 => command prompt.
MySQL®
The world’s most popular open-source database server is the
freely available MySQL DBMS product that is supplied with an
integral SQL-client from which to execute SQL queries from its
mysql> command prompt. MySQL is used throughout this book
to demonstrate the SQL language. The following pages describe
how to install MySQL on both Windows and Linux platforms.
Introducing SQL
13
l6 Click the “Next” button and continue on to complete the
configuration. Now launch the MySQL Command Line
Client from the MySQL group that has been added to At the mysql> prompt
the Windows Start menu and enter your password to open type exit, quit, or \q
the MySQL monitor: then hit Return to close
the MySQL monitor.
Introducing SQL
15
domain (localhost), the user (root), and the password you entered
during the MySQL Server installation process.
17
l5 Click the Test button to test the driver installation, then
close the Configuration dialog box and see the driver now
appear in the ODBC Data Source Administrator list
19
l5 Finally click the Execute button to execute your SQL
statement – to see all current MySQL databases
Summary
• The Structured Query Language (SQL) is the standard
language for communicating with databases
• The Microsoft Query tool can execute SQL queries against the
MySQL DBMS via a MyODBC driver