PDF Beginning MySQL 1st Edition Robert Sheldon download
PDF Beginning MySQL 1st Edition Robert Sheldon download
https://ebookultra.com/download/beginning-silverlight-3-1st-edition-
robert-lair/
https://ebookultra.com/download/beginning-ios-3d-unreal-games-
development-1st-edition-robert-chin/
https://ebookultra.com/download/algebra-and-trigonometry-1st-edition-
sheldon-axler/
https://ebookultra.com/download/learning-mysql-first-edition-williams/
MySQL 4th Edition Paul Dubois
https://ebookultra.com/download/mysql-4th-edition-paul-dubois/
https://ebookultra.com/download/master-of-the-game-sidney-sheldon/
https://ebookultra.com/download/head-first-php-mysql-1st-edition-lynn-
beighley/
https://ebookultra.com/download/high-availability-mysql-cookbook-1st-
edition-alex-davies/
https://ebookultra.com/download/oculomotor-systems-and-perception-1st-
edition-sheldon-m-ebenholtz/
Beginning MySQL 1st Edition Robert Sheldon Digital
Instant Download
Author(s): Robert Sheldon, Geoff Moes
ISBN(s): 9780764579509, 0764579509
Edition: 1
File Details: PDF, 11.98 MB
Year: 2005
Language: english
Beginning MySQL®
Robert Sheldon
Robert Sheldon’s MySQL programming is rooted in ten years of experience working with SQL, as it is
implemented not only in a MySQL environment, but also within SQL Server, Microsoft Access, and Oracle
environments. He has programmed with SQL directly through database interfaces and script files and
indirectly through PHP, JSP, ASP, and ASP.NET applications that connected to various databases
and issued SQL statements. Robert has also managed the maintenance and development of Web sites and
online tools, which has included performing project analysis, developing functional specifications,
and managing database and Web development. He has designed and implemented various Microsoft
Access, SQL Server, and MySQL databases, as well as developed and implemented a variety of Web-based
solutions. In all these roles, he has had to perform numerous types of ad hoc queries and modifications,
build databases, create and modify database objects, create and review embedded statements, and
troubleshoot system- and data-related problems.
In addition to having a technical and SQL background, Robert has written or co-written nine books on
various network and server technologies, including two that have focused on SQL Server design and
implementation, one on SQL programming (based on the SQL:1999 standard), and one on Microsoft
Office Access 2003. The books that Robert has written contain training material that is designed to teach
users specific skills and to test their knowledge of the material covered. Having contracted as the senior
developmental editor for the Microsoft certification team, he brought to these books his experience devel-
oping exam items that helped to focus readers on the skills necessary to perform specific tasks. Robert
has also written and edited a variety of other documentation related to SQL databases and other computer
technologies. He works as an independent technical consultant and writer in the Seattle area.
Geoff Moes
Geoff Moes is a software architect and developer who has designed and implemented databases in
MySQL as well as having designed and implemented software systems in PHP, Java/J2EE, and ASP.NET
that have utilized MySQL databases through various database connectivity interfaces. Geoff received his
bachelor’s degree in Computer Science from Virginia Tech and has worked in the software industry for
18 years. He specializes in software and database architecture and development as it relates to Web-
based systems. He has worked with several database products in addition to MySQL, including SQL
Server, DB2, and Oracle. He has also developed a variety of software applications that have connected to
various databases using several different languages and platforms including Java J2EE/JDBC/EJB,
C++/ODBC, and ASP.NET/ODBC/OLEDB.
Geoff’s publishing credits include “Passing Arrays Between Jscript and C++” (September 7, 2000,
ASPToday.com, under WROX) and three articles published in Windows & .NET Magazine (online):
“Common Internet Hacker Attacks” (December 1, 1998), “Remote Web Administration, Part 2”
(November 1, 1998), and “Remote Web Administration, Part 1” (October 1, 1998). Geoff works as an
independent software consultant in the Washington D.C. metro area. When he is not in front of the
keyboard, he enjoys photography, mountain biking, hiking, and international travel.
Acknowledgments
As with any publication, too many people were involved in the development of Beginning MySQL to
name them all, but we would like to acknowledge those who we worked with the closest in order to
complete this project in a timely manner (and with our sanity still somewhat intact). Our special thanks
goes to Debra Williams-Cauley, the acquisitions editor at John Wiley & Sons, Inc., who pulled this project
together in such a professional and responsive manner. And we particularly want to thank Brian Herrmann,
the development editor on this book who patiently and efficiently (and pleasantly, we might add) kept
this project moving forward, while always paying attention to details and answering our never-ending
stream of questions. We also want to acknowledge David Mercer, the technical editor, for his grasp of the
subject matter and his invaluable input into the book. In addition, we want to acknowledge all the edi-
tors, proofreaders, indexers, designers, illustrators, and other participants whose efforts made this book
possible. Finally, we want to thank our agent, Margot Maley Hutchison, at Waterside Productions, Inc.,
for her help in moving forward on this project and for tending to all the details.
Acknowledgments v
Introduction xxv
Index 811
Welcome to Beginning MySQL, the definitive resource for anyone new to the MySQL database manage-
ment system. As the most popular open source database system in the world, MySQL has gained not only
recognition among its peers but a place of prominence in the worldwide technical industry, ensuring an
ever-growing need for information and training on how to implement a MySQL database and access and
manage data in that database.
Because of its ease of implementation, low overhead, reliability, and lower Total Cost of Ownership (TCO),
MySQL has made remarkable inroads in the database management system market. As a result, the number
of programmers who must connect to a MySQL database and embed SQL statements in their applications
is growing steadily. There are now over five million MySQL installations worldwide, and that number is
increasing rapidly. In addition, MySQL supports connectivity to numerous application languages and envi-
ronments, including C, C++, PHP, ASP, ASP.NET, Java, Perl, C#, and Python, and it can be implemented on
a number of platforms, including Windows, Linux, Unix, Solaris, FreeBSD, Mac OS, and HP-UX.
Corporate implementations continue to grow and include such companies as Yahoo!, Cox Communications,
Google, Cisco, Texas Instruments, UPS, Sabre Holdings, HP, and the Associated Press. Even NASA and the
U.S. Census Bureau have implemented MySQL solutions. MySQL has been proven to work in large deploy-
ments, while reducing system downtimes and administrative overhead and lowering hardware expendi-
tures and licensing costs.
As organizations continue to seek ways to cut their TCO, MySQL will continue to gain in popularity—
and its user-base will continue to grow. As a result, MySQL will gain further ground in becoming a
prominent force in the industry. To meet this demand, Beginning MySQL provides you with a valuable
resource and step-by-step learning tool that supplies you with the background information, examples,
and hands-on exercises that you need to implement MySQL and manage data in its databases. Concepts
are introduced in a logical manner, with each chapter building on the previous chapters. By the end of
this book, you’ll have a complete foundation in MySQL, its implementation, and the methods necessary
to connect to databases and manipulate data.
Because MySQL is such a robust, flexible, and easy-to-implement application, a beginner’s book about
the product will benefit a wide audience, both at home and at the office. The primary audience for
Beginning MySQL can be any of the following readers:
❑ Experienced PHP, Java, or ASP.NET programmers who are developing applications that access
backend databases and who are new to MySQL
In addition to the primary audiences, Beginning MySQL can be useful to the following readers:
❑ The home user who wants to create simple databases for such information stores as address
books, CD collections, or recipes
❑ The home business owner who wants to create database applications for such tasks as managing
customers and contacts, tracking inventories, or recording orders
❑ Managers and owners of small businesses who need database solutions that are both easy and
inexpensive to implement
❑ Group managers in larger companies who need database solutions that meet immediate needs
in their groups
❑ Directors, staff, or volunteers at nonprofit organizations who require database solutions that are
simple and inexpensive to implement
❑ Any other individual who wants to learn how to create and manage a MySQL database that can
support various data-driven applications
Nearly anyone new to MySQL will be able to benefit from Beginning MySQL. In addition, users who
have had experience with earlier versions of MySQL or with other database products will be able to use
the book to refresh and expand their skills.
To benefit from Beginning MySQL, you do not have to have a strong background in databases or any
other computer technology. You should, however, have at least a basic understanding of the following:
❑ You should know to negotiate your way around your operating system environment. The book
focuses on implementing MySQL on Linux and Windows, so whichever one you choose, you
should know how to use that system to copy and access files, add programs, change system set-
tings, or whatever tasks are common to your particular environment. If you’re using a Unix-like
system other than Linux, you should find that much of the Linux-related information will apply
to your system.
❑ You will need to know how to use your Web browser to access the Internet and download files
and view information.
❑ You should know how to use a text editor to create and edit text files.
These requirements are all you really need to use Beginning MySQL successfully and learn about how to
implement MySQL databases and manage data in those databases. For Chapters 17, 18, or 19, you should
have at least basic knowledge of Web development techniques. These three chapters focus on developing
a Web application that accesses data in a MySQL database. Chapter 17 covers PHP, Chapter 18 covers
The next section, which describes the book’s structure, provides additional details about the specifics of
what the book covers.
The structure of Beginning MySQL supports the complete beginner (those new to databases and SQL) as
well as those who are experienced with programming and other database products, but new to MySQL.
The book provides the conceptual and background information necessary for all readers to understand
individual topics, but each chapter is modular to support those readers who simply dip into different
parts of the book to use it as a reference. For example, someone completely new to databases might read
the book from cover to cover, applying information learned in one chapter to the material in the next
chapter. On the other hand, an experienced PHP programmer might want to reference only the chapters
related to SQL statements and PHP connectivity, without having to review chapters on database design
or administration.
Beginning MySQL describes and demonstrates each step necessary to create a MySQL database and access
and manage data in that database. Each chapter correlates with one of the primary tasks necessary to imple-
ment MySQL and to access data, either directly or through an application programming language. The
goal of the book is to provide you with a complete learning experience.
In Chapters 1 through 4, you are introduced to MySQL and relational databases. You are shown the steps
necessary to install MySQL on Windows and Linux, set up the initial MySQL configuration, and access
the MySQL server. You are also shown where to find MySQL components on your system and what tools
are available to access and manipulate data. Finally, you learn how to design a database that conforms to
the relational model. From this information, you will be ready to build a database in which you can store
and manage data.
Chapters 5 through 12 build on the concepts introduced to you in the first four chapters. These chapters
describe how to create databases that store data and help to enforce the integrity of that data. You then
learn how to insert data into those databases, update that data, and then delete the data. You also learn a
variety of methods to retrieve data from the database so that you can display exactly the data you need and
perform operations on that data. You are also shown the steps necessary to copy, import, and export data.
Chapters 17 through 19 are a little different from the other chapters. Each chapter describes how to access
a MySQL database from a specific programming language, including PHP, JSP/Java, and ASP.NET/C#.
You learn how to establish a connection to a database and issue SQL statements against the database. In
each chapter, you will build a data-driven application that allows you to display data that you retrieve
from a MySQL database.
In addition to the 19 chapters in this book, Beginning MySQL includes several appendices that provide
additional information about MySQL and the book. Appendix A provides the answers to the exercises
presented in each chapter. (The exercises are described in the text that follows.) Appendix B includes a
brief description of each application programming interface (API) supported by MySQL, and Appendix
C gives you an overview of features that you can expect to see in the next release of MySQL.
By the end of the book, you will have installed MySQL, configured it, created a database and its tables,
added data to the database and manipulated that data, performed administrative tasks, and created
applications that access the data in the database. To support this process, the chapters contain a number
of elements, including examples that demonstrate how to perform various tasks, Try It Out sections that
provide you with hands-on experience in using MySQL, and exercises that help you better understand
the concepts explained in each chapter.
As you work your way through the you’ll find that MySQL sometimes supports more than one way
that an SQL statement can be written to achieve the same results. As MySQL has evolved, so too have the
statements—to improve performance, simplify the statement, or conform to industry standards. The orig-
inal version of the statements, however, continues to be maintained to support legacy MySQL systems or
to provide portability from one database system to the next. In these situations, you should use whatever
approach is best suited to your particular situation. This sometimes means trying different versions of a
statement to determine which one performs the best. Often, you’ll find that using the simplest version not
only is the easiest approach but will meet most of your needs.
Some of the code that you’ll run in the examples and Try It Out sections is available for download. Be sure
to visit the Wrox Web site at www.wrox.com to determine whether code is available. Generally, anything
that is more than a few lines (anything that you cannot easily type yourself) is available for download.
Each chapter in Beginning MySQL includes a number of elements that demonstrate how to perform spe-
cific tasks related to implementing MySQL databases and managing data in those databases. In addition
to providing a thorough explanation of each concept, the chapters include examples, Try It Out sections,
and exercises.
Examples
For each concept presented in the book, one or more examples are provided to demonstrate that concept.
When appropriate, statement or command syntax precedes the examples. Syntax refers to the basic form
that the statement or command should take. The syntax shows which elements must be included, which
elements are optional, how parameters should be included, and in what order the elements should be
placed. In other words, the syntax provides a blueprint for how a statement or command should be con-
structed. (Chapter 1 provides you with more information about syntax and supplies an example of how
it is used.)
After the syntax has been provided, the chapter includes examples that demonstrate how real-life state-
ments and commands are created. The examples are meant only as a way to demonstrate the actual code.
You are not expected to try out the examples in an actual database environment. With the correct setup, the
statements and commands do indeed work.
If you decide to try out an example, you can use the test database installed by default when you install
MySQL, or you can create your own database for testing purposes. Keep in mind, however, that you have
to pay particular attention to how the database is set up to try out the examples. You cannot assume that a
table named Books used in the examples in one chapter is defined the same as a table named Books in
another chapter. In addition, you cannot assume that, as examples progress through a chapter, they neces-
sarily build on each other, although this is sometimes the case.
Whenever appropriate, a chapter will provide you with details about how the system is set up to demon-
strate the examples. For instance, you’re often provided with the details about how a table is defined and
what data it includes before the examples are provided. You can then use this table setup information to
create your own table in order to try out an example. One example, however, can affect a table in such a
way as to change its original structure or data, so you must be aware of this from one example to the next.
Again, the examples are meant only to demonstrate how a statement or command works. You’re not
expected to try out each example, so if you do, pay close attention to your setup. The book also includes a
number of Try It Out sections, which provide you with a more controlled environment to try out statements
and commands.
Many of the Try It Out sections build on each other as you progress through the book. For example, in
Chapter 4 you design a database, in Chapter 5 you create a database based on that design, and in Chapter 6
you add data to the database. The same database is then used in most of the Try It Out sections that follow
Chapter 6. In fact, you will use the same database to support the data-driven application that you create in
Chapter 17, 18, or 19.
As you work your way through the book, you’ll also find that concepts introduced in earlier chapters
and demonstrated in the related Try It Out sections are not explained in detail in later Try It Out sections.
The assumption in the later Try It Out sections is that you performed the earlier exercises and now know
the material.
Exercises
In addition to the examples and the Try It Out sections, each chapter ends with a set of exercises that
allow you to further build on and test the knowledge that you acquired in that chapter. The answers to
these exercises can be found in Appendix A. Keep in mind, however, that the answers provided for the
exercises sometimes represent only one possible solution. As a result, you might come up with an answer
that is also correct but different from what is shown in Appendix A. If this is the case, you can refer to the
actual chapter content to confirm your answer. The answers shown in the appendix normally represent
the most straightforward solution to the exercise, based on the information in the chapter.
Overall, you’ll find the exercises to be a useful tool to help better comprehend the concepts presented in
the chapter. The exercises, along with the examples and Try it Out sections, provide you with a cohesive
presentation of the material so that you can understand each concept completely. By taking advantage of
each of these elements, you will have a thorough foundation of MySQL and will understand the steps
necessary to install and implement MySQL and manipulate data in a MySQL database.
❑ You should be working on a computer that has a Windows or Linux operating system installed.
You can usually substitute another Unix-like system for Linux, although some of the exercises
might work a little differently from those that focus on Linux.
❑ Eventually, you will need to install the MySQL database management system on your computer.
Chapter 2 explains how to install MySQL.
❑ If you plan to download MySQL or any other files from the Web, you will need high-speed
Internet access.
❑ You will need a text editor such as Vim (for Linux) and Notepad (for Windows).
❑ For Chapters 17, 18, and 19, you will need the appropriate environment in which to implement
your application. For example, PHP requires a Web server such as Apache. JSP/Java requires a
Web server or application server such as JBoss. Depending on your JSP/Java Web server or appli-
cation server, you might also need a special compiler. ASP.NET/C# requires a Web server such as
Internet Information Services. In addition, regardless of the type of application you create, your
system must be set up with the MySQL driver necessary to allow your application to connect to
the MySQL server.
Once you have your system set up the way you need it, you’re ready to begin working your way
through Beginning MySQL.
Conventions
To help you get the most from the text and keep track of what’s happening, a number of conventions are
used throughout the book.
Try It Out
The Try It Out is an exercise you should work through, following the text in the book.
How It Works
After each Try It Out, the code you’ve typed will be explained in detail.
Tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.
❑ New terms and important words are italicized when they are introduced.
❑ Keyboard strokes are shown like this: Ctrl+A.
❑ File names, URLs, and code in the text are shown like so: persistence.properties.
❑ Code is presented in two different ways:
In code examples we highlight new and important code with a gray background.
The gray highlighting is not used for code that is less important in the present
context or has been shown before.
Source Code
As you work through the examples in this book, you may choose either to type all the code manually or
to use the source code files that accompany the book. Much of the source code used in this book is
available for download at http://www.wrox.com. (Generally, if the code in an example or in a step in a
Try It Out section is only a few lines, that code is not included.) Once at the site, simply locate the book’s
title (either by using the Search box or by using one of the title lists) and click the Download Code link
on the book’s detail page to obtain all the source code for the book.
Because many books have similar titles, you may find it easiest to search by ISBN; for this book the
ISBN is 0-764-57950-9.
Once you download the code, just decompress it with your favorite compression tool. Alternately, you can
go to the main Wrox code download page at http://www.wrox.com/dynamic/books/download.aspx
to see the code available for this book and all other Wrox books.
Errata
We make every effort to ensure that there are no errors in the text or in the code. No one is perfect, though,
and mistakes do occur. If you find an error in one of our books, such as a spelling mistake or faulty piece
of code, we would be very grateful for your feedback. By sending in errata, you may save another reader
hours of frustration, and at the same time you will be helping us provide even higher-quality information.
To find the errata page for this book, go to http://www.wrox.com and locate the title using the Search
box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page you
can view all errata submitted for this book and posted by Wrox editors. A complete book list including
links to each’s book’s errata is also available at www.wrox.com/misc-pages/booklist.shtml.
If you don’t spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml
and complete the form there to send us the error you have found. We’ll check the information and, if appro-
priate, post a message to the book’s errata page and fix the problem in subsequent editions of the book.
p2p.wrox.com
For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-based system
for you to post messages relating to Wrox books and related technologies and interact with other readers
and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choos-
ing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow
readers are present on these forums.
At http://p2p.wrox.com you will find a number of different forums that will help you not only as you
read this book, but also as you develop your own applications. To join the forums, just follow these steps:
You can read messages in the forums without joining P2P, but in order to post your own messages, you
must join.
Once you join, you can post new messages and respond to messages other users post. You can read mes-
sages at any time on the Web. If you would like to have new messages from a particular forum e-mailed
to you, click the Subscribe to this Forum icon by the forum name in the forum listing.
For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to ques-
tions about how the forum software works as well as many common questions specific to P2P and Wrox
books. To read the FAQs, click the FAQ link on any P2P page.
In the world of online auction houses, instant mortgages, worldwide reservations, global
communication, and overnight deliveries, it’s not surprising that even the least technically savvy
individuals in our culture are, to some degree, familiar with the concept of a database. As anyone
who works with data knows, databases form the backbone for this age of information, and access
to those databases can determine one’s ability to perform critical tasks effectively and efficiently.
To meet the ever-increasing demands for information, programmers are continuously building
bigger and better applications that can access and modify data stored in various database systems.
Yet in order to create these applications, programmers must have some knowledge of the systems
that contain the needed data.
Over the years, as the demands for information have grown, so too have the database systems
that have attempted to meet these demands. However, along with this evolution, we have seen an
increase in the costs associated with storing data as well as an increase in the demand for products
that can run on multiple platforms and can be optimized based on the needs of specific types of
organizations. In response to this changing climate, MySQL has emerged as the most popular
open-source database management system (DBMS) in the world. Consequently, organizations
everywhere are jumping on the MySQL bandwagon, increasing the demand for those who know
how to use MySQL to manage data and those who know how to create applications that can access
data in MySQL databases.
In learning to use MySQL, whether to work directly in the MySQL environment or create data-driven
applications, an individual should have a thorough understanding of how MySQL, as a relational
database management system (RDBMS), allows you to manage data and support applications that
rely on access to MySQL data. To this end, this chapter introduces you to MySQL and provides
you with an overview of databases, RDBMSs, SQL, and data-driven applications. By the end of
the chapter, you will understand the following concepts:
What Is a Database?
Over the years, the term database has been used to describe an assortment of products and systems that
have included anything from a collection of files to a complex structure made up of user interfaces, data
storage and access mechanisms, and client/server technologies. For example, a small company might
store payroll records in individual files, while a regional electric company uses an integrated system to
maintain records on all its customers; generate electric bills to those customers; and create reports that
define power usage patterns, profit and loss statements, or changes in customer demographics. In both
cases, the organizations might refer to each of their systems as databases.
Despite how a database is used, the amount of data that it stores, or the complexity of the data, a num-
ber of common elements define what a database is. At its simplest, a database is a collection of data that
is usually related in some fashion. For instance, a database that a bookstore uses might contain informa-
tion about authors, book titles, and publishers. Yet a database is more than simply a collection of related
data. The data must be organized and classified in a structured format that is described by metadata,
which is data that describes the data being stored. In other words, the metadata defines how the data is
stored within the database. Together, the data and the metadata provide an environment that logically
organizes the data in a way that can be efficiently maintained and accessed.
One way to better understand what constitutes a database is to use the analogy of a telephone book. A
phone book contains the names, addresses, and phone numbers of most of the telephone customers in
a particular town or region. If you think of that phone book as a database, you find a set of related data
(the names, addresses, and phone numbers of the telephone customers) and you find a structured
format (the metadata) that is defined by the way that the pages are bound and by how the information
is organized. The phone book provides a system that allows you easy and efficient access to the data
contained in its pages. Without the structure of the phone book, it would be next to impossible to locate
specific customer data.
Take a look at an example to help illustrate how to structure a hierarchical database. Suppose you’re
working with a database that stores parts information for a company that manufactures wind generators.
Each model of wind generator is associated with a parent record. The parts that make up that model are
then divided into categories that become child records of the model’s parent record, as shown in Figure 1-1.
In this case, the parent record — Wind Generator Number 101 — is linked to three child records: Tower
assemblies, Power assemblies, and Rotor assemblies. The child records are then divided into subcategories
that are assigned their own child records. As a result, the original child records now act as parent records
as well. For example, the Tower assemblies record is a parent of the Towers record but a child of the
Wind Generator Number 101 record.
As you can see in the figure, a parent record can be associated with multiple child records, but a child
record can be associated with only one parent record. This structure is similar to what you might see in a
directory structure viewed through a graphical user interface (GUI) file management application, such as
Windows Explorer. At the top of the directory structure would be Wind Generator Number 101. Beneath
this, would be Tower assemblies, Power assemblies, and Rotor assemblies, each with their own set of
subdirectories.
After its introduction, the hierarchical data model achieved a great deal of success. One of the most
popular implementations of this model is found in IBM’s Information Management System (IMS),
which was introduced in the 1960s and is still widely used on IBM mainframe computers.
However, despite the popularity of the hierarchical model, it is unsuitable for many of today’s applications.
Inherent in the simplicity of the parent-child organization is a rigid structure that results in a cumbersome
navigation process that requires application developers to programmatically navigate through the
connected records to find the necessary information. Records must be accessed one at a time by moving
up and down through the hierarchical levels, which often made modifications to the database and
application a complicated, time-consuming process. In addition, the hierarchical structure cannot support
complex relationships between records. For example, if you return to the wind generator database example,
you discover that Figure 1-1 doesn’t show a record for the belts used to connect the generators to the
shafts. If you were to create a child record for belts, should it be added under the Generators record or
the Shaft assemblies record? The hierarchical design makes it difficult to fully represent the relationship
that exists between the belts and the generators and shafts. Indeed, a child record can be associated with
only one parent record.
Wind Generator
Number 101
Tower Rotor
assemblies assemblies
Power
assemblies Rotation Yaw
Battery
Anemometers packs
Shutdown
systems
Wiring
Generators Dump load
systems
Cables Connectors
Brushes Magnets Regulators Heaters
Coils
Wiring
Commutators
Figure 1-1
Employees
Max N.
Orders
Sarah W.
Order 1002
Customers
Order 1003
Wind
generators
Wind Wind
generators generators
Number 103 Number 102
Wind
generators
Number 101
Figure 1-2
The network model still has many of the disadvantages of the hierarchical model, but it provides far
more flexibility in allowing programmers to navigate through records. Despite the flexibility, developers
must still program record navigation within the application. In addition, any changes to the database
or application can result in complicated updates. A database must be well planned in advance, taking
into account record navigation at the application level.
However, a relational database is independent of the application. It’s possible to modify the database
design without affecting the application because the relational model replaces the parent-child framework
with a structure based on rows and columns that form tables of related data. As a result, you can define
complex relationships between the tables, without the restrictions of earlier models.
For example, suppose you want to change the original wind generator database that you saw in Figure 1-1
to a relational database. The database might include a table for the individual parts and a table of the
individual categories of parts, as shown in Figure 1-3. As you can see from the illustration, the Parts table
includes a list of parts from different areas of the wind generator. The table could contain every part for
the entire wind generator, with each row in the table representing a specific part, just as a record in the
hierarchical database represents a specific part. For example, the guy wire assembly (in the first row of
the Parts table) is a component of the tower assembly, and the generator (in the fifth row) is a component
of the power assembly.
Each row in the Parts table represents one part. The part is assigned a unique part ID, a name, and a
reference to the category to which it belongs. The Categories table lists each category. Note that the last
column in the Parts table references the first column in the Categories table. A relationship exists between
these two tables. For instance, the brushes product has been assigned a PartID value of 1004. If you look
in the CatID column for this product, you see that it contains a value of 504. If you now look at the
Categories table, you find that 504 refers to the Generator category, which is itself a part. Because of this
structure, programmers are less restricted when moving through data, resulting in applications that can
be more flexible when retrieving information and databases that can better accommodate change after
the applications have been written.
Don’t be concerned if you do not fully grasp the concepts of tables, rows, and columns or the relation-
ships between the tables. Chapter 4 discusses the relational model in greater detail.
Parts Categories
PartID PartName CatID CatID CatName Parent
1001 Guy wire assembly 503 501 Wind Generator 101 NULL
1002 Magnet 504 502 Rotor assembly 501
1003 Regulator 505 503 Tower assembly 501
1004 Brushes 504 504 Generator 506
1005 Generator 506 505 Dump load system 506
1006 Dump load system 506 506 Power assembly 501
1007 Power assembly 501
1008 Tower assembly 501
1009 Rotor assembly 501
Figure 1-3
As the popularity of the relational model has grown, so too has the number of database products that
use this model to store and manage data. Included in the family of relational products are DB2, Oracle,
SQL Server, and of course, MySQL. However, a relational database alone is not enough to provide the
type of data management, storage, connectivity, security, analysis, and manipulation that is required of a
dynamic information store. For this, you need a complete management system that works in conjunction
with the relational database to provide the full spectrum of database services.
At the very least, a DBMS must store data and allow data to be retrieved and modified in a way that
protects the data against operations that could corrupt or insert inconsistencies into the data. However,
most systems provide many more capabilities. In general, nearly any comprehensive DBMS supports the
following types of functionality:
❑ Managing storage
❑ Maintaining security
❑ Maintaining metadata
❑ Managing transactions
❑ Supporting connectivity
❑ Optimizing performance
❑ Providing back-up and recovery mechanisms
❑ Processing requests for data retrieval and modification
Emerging as a major player in the RDBMS market is MySQL. As with other RDBMS products, MySQL
provides you with a rich set of features that support a secure environment for storing, maintaining, and
accessing data. MySQL is a fast, reliable, scalable alternative to many of the commercial RDBMSs available
today. The following list provides an overview of the important features found in MySQL:
❑ Scalability: MySQL can handle large databases, which has been demonstrated by its implemen-
tation in organizations such as Yahoo!, Cox Communications, Google, Cisco, Texas Instruments,
UPS, Sabre Holdings, HP, and the Associated Press. Even NASA and the US Census Bureau
have implemented MySQL solutions. According to the MySQL product documentation, some of
the databases used by MySQL AB, the company that created MySQL, contain 50 million records,
and some MySQL users report that their databases contain 60,000 tables and 5 billion rows.
❑ Portability: MySQL runs on an assortment of operating systems, including Unix, Linux,
Windows, QS/2, Solaris, and MacOS. MySQL can also run on different architectures, ranging
from low-end PCs to high-end mainframes.
❑ Connectivity: MySQL is fully networked and supports TCP/IP sockets, Unix sockets, and
named pipes. In addition, MySQL can be accessed from anywhere on the Internet, and multiple
users can access a MySQL database simultaneously. MySQL also provides an assortment of
application programming interfaces (APIs) to support connectivity from applications written in
such languages as C, C++, Perl, PHP, Java, and Python.
❑ Security: MySQL includes a powerful system to control access to data. The system uses a host- and
user-based structure that controls who can access specific information and the level of access to
that information. MySQL also supports the Secure Sockets Layer (SSL) protocol in order to
allow encrypted connections.
❑ Speed: MySQL was developed with speed in mind. The amount of time it takes a MySQL
database to respond to a request for data is as fast as or faster than many commercial RDBMSs.
The MySQL Web site (www.mysql.com) provides the results of numerous benchmark tests that
demonstrate the fast results you receive with a MySQL implementation.
❑ Ease of use: MySQL is simple to install and implement. A user can have a MySQL installation
up and running within minutes after downloading the files. Even at an administrative level,
MySQL is relatively easy to optimize, especially compared to other RDBMS products.
❑ Open-source code: MySQL AB makes the MySQL source code available to everyone to
download and use. The open-source philosophy allows a global audience to participate in the
review, testing, and development of code. (See the Open-Source Movement section below for
information about open-source technology.)
For specific information about the most current MySQL licensing structure, visit the MySQL site at
www.mysql.com. For information about the GNU GPL, visit the GNU licensing site at
www.gnu.org/licenses.
The open-source nature of MySQL is part of a worldwide movement that promotes the free access of
application source code. As a result, users are allowed to download and use open-source applications for
free. One of the most well known examples of this technology is the Linux operating system, which has
been instrumental in unifying the open-source community and promoting a wider base of users and
developers who test and contribute to the operating system’s development. The same is true of MySQL,
which is reported to be the most popular open-source RDBMS in the world. As an open-source application,
developers everywhere contribute to the development process, and millions of users test new versions
of the application as it is being developed.
As applications such as MySQL and Linux continue to see a steady growth in their global user base, so
too does the acceptance of the open-source philosophy, evidenced by the increasing number of other
types of applications and technologies that now participate in the open-source movement, providing a
richer user experience, a more robust developer environment, and a wider spectrum of options for
everyone.
There is some debate about what SQL stands for and how to pronounce it. In some sources, you see SQL
defined as an acronym that means Structured Query Language, yet other sources treat SQL as simply
the three letters that stand for the language. The American National Standards Institute (ANSI), which
published the SQL:2003 standard, makes no mention of “structured query language” and treats SQL
simply as the three letters. As a result, no definite resource says that SQL stands for Structured Query
Language, despite the fact that many publications define it this way.
What is SQL?
SQL is, above all else, a computer language used to manage and interact with data in a relational
database. SQL is the most universally implemented database language in use, and it has become the
standard language for database management. SQL works in conjunction with a RDBMS to define
the structure of the database, store data in that database, manipulate the data, retrieve the data, control
access to the data, and ensure the integrity of the data. Although other languages have been developed
to implement the relational model, SQL has emerged as the clear winner.
Nearly all RDBMSs implement some form of SQL in order to manage their relational database. This is
true not only for MySQL, but also for SQL Server, DB2, Oracle, PostgreSQL, and all the major players in
the world of RDBMSs. However, do not confuse SQL with the programming languages used to develop
the RDBMS. For example, MySQL is built with C and C++. The functions that such an application performs
in order to support connectivity, provide APIs, enable network access, or interact with client tools are
carried out at the C and C++ programming level. The primary purpose of SQL is to allow the RDBMS to
interact with the data. The C and C++ environment provides the structure that houses the SQL environ-
ment, which itself allows you to define and interact with the data. In other words, the RDBMS facilitates
the ability of SQL to manage data.
Figure 1-4 illustrates how SQL interacts with the MySQL RDBMS. In this figure, MySQL is running as a
server on a specific platform such as Linux or Unix. The database, stored either internally or externally,
depending on your storage configuration, hosts the actual database files. Although the RDBMS facili-
tates (through the C/C++ applications) the creation and maintenance of the database and the data
within the database, SQL actually creates and maintains the database and data.
MySQL SQL
RDBMS database
C/C++
SQL statements
Figure 1-4
In the late 1970s, IBM released System R to a number of its customers for evaluation. The development
and release of System R brought with it increased attention to relational databases, RDBMSs, and
SQL, and reconfirmed to the public IBM’s commitment to the relational model. Soon a group of engineers
formed Relational Software, Inc., a company whose primary goal was to develop a RDBMS system
based on SQL. Before long, the company released its own product — Oracle — the first commercial
RDBMS to hit the market. It wasn’t until 1981 that IBM released their first commercial RDBMS — SQL/DS.
ANSI updated the standard in 1989 (SQL-89) and again in 1992 (SQL-92). SQL-92 represented a major
revision to the language and included expanded and improved features, some of which exceeded the
capabilities of existing RDBMSs. In fact, SQL-92 was substantially longer than SQL-89 in an attempt to
address many of the weaknesses of the earlier standard.
Because of the significant expansion of the standard, SQL-92 defined three levels of conformance:
❑ Entry: This level represented the most basic stage of conformance, and was based primarily on
the SQL-89 standard, with only a few improvements.
❑ Intermediate: Although this level represented significant advancements to the product, it was
believed that most products could achieve compliance.
❑ Full: A RDBMS had to be in complete compliance with the standard.
In 1999, ANSI, along with the International Organization for Standardization (ISO) published SQL:1999,
the first complete update to the SQL standard since 1992. However, during those seven years, interim
standards were published to incorporate features that RDBMS vendors were already being implementing.
These interim publications were then incorporated in the SQL:1999 standard, which represented another
significant expansion of the standard.
Because most products reached only an Entry level of conformance to SQL-92, the SQL:1999 standard
took a different approach to conformance levels. To be in conformance to the new standard, a RDBMS
had to be in compliance with Core SQL. Core SQL contained all the features of Entry level SQL-92, many
of the features of Intermediate level, and some of the features of Full level, plus some features new to
SQL:1999. In addition to claiming Core SQL conformance, a RDBMS could claim conformance to one of
the supported packages. A package is a set of features that a vendor could implement in a RDBMS. The
SQL:1999 standard supported the following packages:
Most RDBMSs, including MySQL, conform to the Entry level of SQL-92 and achiev some confor-
mance to Core SQL in SQL:1999. However, ANSI and ISO have released yet another version of the
standard — SQL:2003. In many ways, the new standard merely reorganizes and makes corrections
to SQL:1999. However, the latest standard does include additional features that were not part of
SQL:1999, particularly in the area of Extensible Markup Language (XML). As a result, compliance
with SQL:1999 does not necessarily imply compliance to SQL:2003.
With the advent of SQL:2003, future releases of RDBMS products will inevitably change, and some
vendors are already working on achieving compliance with the new standard. However, as of today,
no product claims compliance to SQL:2003.
You can purchase the ANSI/ISO SQL:2003 standard online at the ANSI eStandards Store
(http://webstore.ansi.org). The standard is divided into 14 parts, which you must purchase
individually.
Java and C# are both examples of object-oriented programming languages. In these languages, objects
interact with one another in a way that addresses complex programming issues that cannot be easily
addressed with traditional procedural languages.
A good example of the object-oriented nature of some of the extended features in RDBMSs is the stored
procedure. A stored procedure is a collection of SQL statements that are grouped together to perform a
specific operation. The SQL statements are saved as a single object stored in the database and that users
can evoke as needed.
By the mid-1990s, most RDBMS products had implemented some form of the stored procedure. To
address this trend, ANSI released in 1996 an interim publication referred to as SQL/PSM, or PSM-96.
(PSM refers to persistent stored module.) A PSM is a type of procedure or function stored as an object in
the database. A procedure is a set of one or more SQL statements stored as a unit, and a function is a
type of operation that performs a specific task and then returns a value.
The SQL/PSM standard defined how to implement PSMs in SQL. Specifically, SQL/PSM included the
language necessary to support stored procedures (which were referred to as SQL-invoked procedures in
the standard). SQL/PSM was later incorporated into the SQL:1999 standard.
The problem that ANSI ran into when trying to standardize the SQL language related to stored procedures
is that the way in which stored procedures were implemented from product to product varied widely.
As a result, the manner in which stored procedures are called and retrieved can be very different not
only between products and the SQL:1999 standard, but also among the products themselves. As a result,
the implementation of stored procedures remains very proprietary, with few products conforming to the
actual standard.
MySQL currently does not support stored procedures, although SQL AB is including this functionality
in version 5.0. The stored procedure functionality is based on the SQL:2003 standard.
The differences among the products extend beyond only stored procedures. Other features have experi-
enced the same fate as stored procedures because so many of these features had been implemented prior
to the standardization of related SQL statements. Still, many of SQL’s advanced features, with their
object-oriented characteristics, are here to stay, as can be seen in both the SQL:1999 and SQL:2003 stan-
dards and in the RDBMS products, making SQL an object-relational database language and the RDBMS
products object-relational database management systems.
Traditional programming languages, which range from Fortran to C, are considered to be procedural
languages; that is, they define how to carry out an application’s operations and the order in which to
carry them out. SQL, on the other hand, is nonprocedural in nature. It is concerned primarily with the
results of an operation. The host language determines how to process the operation. Of course, this doesn’t
mean that SQL doesn’t include procedural elements. For example, stored procedures are such an
element, and certainly RDBMS vendors recognize the need for at least some procedural functionality.
Yet these procedural elements do not make SQL a procedural language. SQL doesn’t have many of the
basic programming capabilities of the other languages. As a result, you cannot build an application with
SQL alone. You must use a procedural language that works in conjunction with SQL to manipulate data
stored in a RDBMS.
SQL Statements
SQL is made up of a set of statements that define the structure of a database, store and manage data
within that structure, and control access to the data. At the heart of each SQL statement is a syntactical
structure that specifies how to create the statement can be created. The syntax acts as blueprint for
building statements that the RDBMS interprets. Most RDBMS products provide little leeway for state-
ments that don’t adhere strictly to the syntactical foundations. As a result, you should know how to read
and interpret statement syntax if you plan to use SQL in your applications or access data in an SQL
database.
When you first look at the complete syntax for any statement, it might seem overwhelming, depending on
the statement. For some statements, there are relatively few elements, so interpretation is easy. However,
other syntax can be pages long. Despite the complexities of a particular statement, the basic syntax
elements are the same, and if you learn how to interpret those elements, you can, with practice, understand
any syntax presented to you.
The elements comprising a syntactic structure can vary from reference to reference and from product
to product, although in many cases, the symbols used are the same. This book follows ANSI’s SQL:2003
standards. You may encounter partial syntax throughout this book. In some cases, there are simply too
many syntactic elements, and many of those elements are rarely implemented. Whenever you want to be
certain that you’re seeing a statement’s syntax in its entirety, be certain to check the MySQL documentation.
<table definition>::=
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] <table name>
(<table element> [{, <table element>}...])
[ENGINE = {BDB | MEMORY | ISAM | INNODB | MERGE | MRG_MYISAM | MYISAM}]
<table element>::=
{<column name> <type> [NOT NULL | NULL] [DEFAULT <value>] [AUTO_INCREMENT]}
| {PRIMARY KEY (<column name> [{, <column name>}...])}
| {INDEX [<index name>] (<column name> [{, <column name>}...])}
The syntax shown here does not represent the CREATE TABLE statement in its entirety, but it does
include the fundamental components. Chapter 5 examines the table definition syntax in far more
detail, but for now, the primary concern is that you learn how to interpret SQL statement syntax.
The syntax method employed here is referred to as BNF (Backus Naur Form) notation. Most resources
that discuss syntax for SQL statements use BNF notation or something similar to this.
Before examining the syntax example in detail, review the symbols used as part of syntax notation.
The following conventions define how to create a statement, based on the meaning of the symbols
within the context of the syntax:
❑ Vertical bar ( | ): The vertical bar can be interpreted to mean “or.” Whenever you can choose
from two or more options, those options are separated with a vertical bar. For example, in the
sixth line, you can choose either NOT NULL or NULL.
❑ Square brackets ( [ ] ): A set of square brackets indicates that the syntax enclosed in those brackets
is optional.
❑ Angle brackets ( < > ): A set of angle brackets indicates that the syntax enclosed is a place-
holder, in which case, you must insert a specific value in place of the angle brackets and the
text within those brackets. If the meaning of the placeholder is not self-evident, a later section
within the syntax usually defines it.
❑ Curly brackets ( { } ): A set of curly brackets indicates that the syntax enclosed in those brackets
should be treated as a unit. As a result, if one element within the brackets is used, all elements
are used, unless a vertical bar separates options within the brackets.
❑ Three periods (...): A set of three periods means that the clause that immediately precedes the
periods can be repeated as often as necessary.
❑ Two colons/equal sign (::=): The colon/equal sign construction defines placeholders. Literally,
it is the equivalent to an equal sign. The syntax to the right of the symbols defines the specified
placeholder to the left.
Normally, keywords are represented in all uppercase to distinguish them from placeholders, but SQL is
a case-insensitive language, so the use of uppercase is meant only as a way to write more readable code.
You could also write Create Table, create table, or CREate taBLE, and MySQL would interpret the code
in the same way.
Not only is SQL indifferent to capitalization, it also isn’t concerned with tabs, extra spaces, or line
breaks. In theory, you could write your entire SQL statement on one line, or you could place each word
on separate lines. However, it’s recommended that you construct your statements in such a way that
they are easy to read and understand, so breaking a statement into several lines is a common approach
to take.
Returning to the example syntax and reviewing it line by line, the syntax begins by identifying the type
of statement that is being defined:
<table definition>::=
Literally, the syntax means that the <table definition> placeholder is equivalent to the syntax that
follows. SQL-related documentation often omits this introductory line, and it is seldom necessary at the
beginning of the syntax. Usually, the syntax itself clearly defines the statement’s purpose. However, it’s
included here so that you recognize it should you run into it in SQL documentation. To review the second
line of the syntax:
This line represents the actual first part of a CREATE TABLE statement. Notice that the keyword TEMPORARY
separates the CREATE TABLE keywords. Because square brackets enclose this keyword, the keyword is
optional. You would include it only if you plan to create a temporary table. (Temporary tables are
discussed in Chapter 5.) Because of the optional keyword, a table definition can begin with CREATE
TABLE or CREATE TEMPORARY TABLE.
The next part in this line of syntax is the keywords IF NOT EXISTS. Again, these keywords are
optional and would be included only if you want to check for the existence of a table with the same
name. Note, however, that when a set of brackets encloses multiple words in this manner, all the keywords
are included or none are included. You would not use IF, NOT, or EXISTS alone within this context of
this part of the statement. In other words, you would never create a statement that begins with the
following:
Notice that the final element in this line of syntax is the <table name> placeholder. This is the position
within the statement in which you provide a name for the table that you’re creating. When the table is
added to the database, it is assigned the name that you provide here, and this is the name that you use
whenever referring to the table. Now look at the next line of syntax:
The important point to remember is that at least one <table element> is required, but you can
include as many as necessary. However, this is when the syntax gets a little trickier. Notice that several
elements are enclosed in square brackets — [{, <table element>}...] — telling you that this part
of the syntax is optional. However, curly brackets group together parts of the syntax within the square
brackets — {, <table element>} — and they are followed by three periods. The curly brackets mean
that the elements within those brackets must be kept together, and the periods mean that the group of
elements can be repeated as often as necessary. As a result, whenever you include an additional
<table element> in your statement, you must precede it with a comma, but you can do this as many
times as necessary. For example, if the statement includes four table elements, your syntax would
be as follows:
As you can see, when you include more than one <table element>, you must follow each one with a
comma, except for the last one. And keep in mind that parentheses must enclose them all. Moving on to
the next line of syntax:
One of the first things that you notice is that square brackets enclose the entire line, which means that
the entire line is optional. The line defines the type of table that you plan to create. If you do include
this line in your CREATE TABLE statement, then you must include ENGINE = plus one of the table
type options. You can tell that you’re allowed to select only one option because a vertical bar separates
each option. You could read this as BDB or MEMORY or ISAM or INNOBD, and so on. For example, if
you want to define the table as an INNODB table, you would include the following line in your syntax:
ENGINE = INNODB
You should now have a basic understanding of how to create a CREATE TABLE statement. However,
as you may recall, the <table element> placeholder could not be easily defined by its placement or
usage. As a result, the syntax goes on to define the components that can make up a <table element>.
You can tell that the syntax defines the <table element> placeholder because it precedes the
definition with the actual placeholder, as shown in the first line in the next section of syntax:
<table element>::=
From this, you know that whatever follows is part of the syntax that defines the <table element>
placeholder. Before you look too closely at the first line in the <table element> definition, take a look
at all three lines that make up that definition:
A primary key is a constraint placed on one or more columns within a table to indicate that the columns
act as the primary identifier for each row in that table. Values within a primary key’s columns must be
unique when taken as a whole. You learn about primary keys in Chapter 5, which discusses how to
create a table.
This line defines a column within the table. Each column definition must include a name (<column
name>) and a data type (<type>). A data type determines the type of data that can be stored in a
table. The line also includes three optional elements. The first of these is [NOT NULL | NULL], which
means that you can set a column as NOT NULL or NULL. A null value indicates that a value is undefined
or unknown. It is not the same as zero or blank. Instead it means that a value is absent. When you
include NOT NULL in your column definition, you’re saying that the column does not permit null
values. On the other hand, the NULL option permits null values.
The next optional element in the column definition is [DEFAULT <value>]. This option allows you to
define a value that is automatically inserted into a column if a value isn’t inserted into the column when
you create a row. When you include the DEFAULT keyword in your column definition, you must include
a value in place of the <value> placeholder.
The final optional element of the column definition is [AUTO INCREMENT]. You include this option in
your definition if you want MySQL to automatically generate sequential numbers for this column
whenever a new row is added to the table.
With regard to the three options available in the <table element> definition, the column definition is
the one you use most often. However, as stated above, you can choose any of three options, so take a
look at the second line:
The purpose of this line is to define a primary key for the table. If you choose this option, you must
include the PRIMARY KEY keywords and at least one column name, enclosed in parentheses. The
elements contained in the square brackets — [{, <column name>}...] — indicate that you can
include one or more additional columns and that a comma must precede each additional column.
For example, if you base your primary key on three columns, your syntax is as follows:
Don’t worry if you don’t understand how primary keys are created or how they can be made up of
multiple columns. Primary keys are discussed in detail in Chapter 5.
This line creates an index. If you use this option, you must include the INDEX keyword and at least one
column name, enclosed in parentheses. As was the case when creating a primary key, you can also
include additional columns, as long as a comma precedes each additional column. However, unlike a
primary key, the index name is optional. It’s up to you whether you want to name the index, although
naming all objects in a database is generally considered a good practice.
You should now have a fairly good sense of how to interpret a statement’s syntax. As you have seen from
the table definition example, the syntax for an SQL statement can contain many elements. However,
once you’re comfortable with syntax structure and how symbols define this structure, you should be
able to interpret the syntax for nearly any SQL statement (albeit some statements might present a far
greater challenge than other statements). The next section discusses how to use this syntax to create an
SQL statement.
Below is an example of a statement based on the table definition syntax. The following CREATE TABLE
statement creates a table named Parts:
The first thing to note is that the CREATE TABLE example is a single SQL statement. Notice that it ends
with a semi-colon, which is sometimes referred to as a terminator. When you access a MySQL database
directly (for example, by using the mysql client utility), you must terminate each SQL statement with a
semi-colon.
As mentioned earlier, SQL is indifferent to extra spaces, tabs, and line breaks. However, the statement is
written in such a way as to facilitate readability and to make it easier to explain each element. For example,
the table elements are indented and the opening and closing parentheses are placed on their own lines.
The code is merely a comment and is not processed by MySQL. (In fact, you normally wouldn’t use
comments when working with MySQL interactively, but the comment is included here to demonstrate
how they work.) It is there only to provide information to anyone who might be viewing the code.
Adding comments to your code to explain the purpose of each part or to provide any special information
is always a good idea. Comments are particularly useful when updating code you had created in the
past or when someone else is working on code that you created. Comments are also very useful if you’re
trying to debug your code.
You can also create a comment by preceding the text with double dashes (--). However, the comment
cannot include any line breaks.
As you can see from the line of code, a comment begins with /* and ends with */. Everything between
the two symbols, including line breaks, is considered part of the comment and therefore ignored by
MySQL when processing the SQL statements.
The next line of code is the first line of the actual CREATE TABLE statement:
As you can see, the line includes the CREATE TABLE keywords and the name of the new table — Parts.
If you refer to the related line of syntax, you can see how to form the CREATE TABLE clause :
Notice that the optional keyword TEMPORARY and the optional keywords IF NOT EXISTS are not
included in the clause, only the required elements. Now take a look at the <table element>
definitions:
(
PartID INT NOT NULL,
PartName VARCHAR(40) NOT NULL,
CatID INT NOT NULL,
PRIMARY KEY (PartID)
)
This part of the CREATE TABLE statement includes four <table element> components. The first
three represent column definitions and the last represents a primary key definition. The elements are
enclosed in parentheses and separated by commas. If you compare this to the syntax, you can see
how the <table element> placeholders represent each component:
F O OT N OT E S :
[76] Indeed they could not with much consistence condemn him
of neglect, after they had previously and unanimously voted the
following resolution, which was their 25th:
“The Court are of opinion, that while the Ramillies (the Admiral’s
own ship) was firing in going down, the Trident and ships
immediately ahead of the Ramillies proved an impediment to the
Ramillies continuing to go down.”
It was proved, too, beyond contradiction, that he could not
foresee that the French fleet would not stay for him, as they
remained with their sails aback to the mast; and that he must
have been up with them in ten or fifteen minutes, if the
impediment had not happened from the Trident and Princess
Louisa.
[77] I do not mean to say that none of the Judges on the Court-
Martial had really been convinced that by the severity of the law
they could not acquit the Admiral, though they thought him guilty
of only a momentary error of judgment.
[78] I say, powerful man, not man in power, for Lord Hardwicke,
Lord Anson, the Duke of Newcastle, &c., were not then in place—
but them Geary must have meant, for he could not fear
disobliging Mr. Pitt and Lord Temple by speaking out, when it was
his silence that prejudiced them. It was plain Geary thought, what
happened so soon afterwards, that the command of the Admiralty
would still be in Lord Anson.
[79] [Lord Hardwicke. Lord Anson had married his daughter. It
must, however, be admitted, that our author’s language in this
passage is as obscure as his reasoning is unfair and inconclusive.
—E.]
[80] Mr. Pitt, loud enough to be heard by half the House, cried
out, “I wish you joy of him.”
CHAPTER XI.
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.
ebookultra.com