Tải bản đầy đủ
Chapter 10: Managing Databases with Microsoft SQL Server 2014, Oracle Database, and MySQL 5.6

Chapter 10: Managing Databases with Microsoft SQL Server 2014, Oracle Database, and MySQL 5.6

Tải bản đầy đủ



CHAPTER 10   Managing Databases with Microsoft SQL Server 2014, Oracle Database, and MySQL 5.6

491

The material in these chapters describes the basic features and functions
of Microsoft SQL Server 2014 in Chapter 10A, Oracle Database 12c (and Oracle
Database Express Edition 11g Release 2) in Chapter 10B, and MySQL 5.6 in
Chapter 10C. The discussion in these chapters uses the View Ridge Gallery database from Chapter 7, and it parallels the discussion of SQL DDL, DML, and SQL/
PSM in Chapter 7 and the discussion of database administration tasks in Chapter 9.
These DBMS products are large and complicated systems. In these chapters,
we will only be able to scratch the surface of what each is capable of. Your goal
should be to learn sufficient basics so you can continue learning on your own or in
other classes.
The topics and techniques discussed in these chapters will usually also apply
to earlier versions of each software product. For example, the material on Microsoft
SQL Server 2014 will also apply to SQL Server 2012, to SQL Server 2008 R2, and
even to the earlier SQL Server 2005, though the exact functions of the earlier versions vary a bit from SQL Server 2014. Similarly, the material on Oracle Database
12c will usually work with Oracle Database 11g Release 2, and the material on
MySQL 5.6 will work with MySQL 5.5.

Installing the DBMS
In this section of each online chapter, we will discuss the various versions of each DBMS
available, recommend which version you should use, and cover important points about
DBMS installation and setup. Each of these DBMS products has a freely available ­version
that is easy to download and install and that can be used with most of the material in this
book (the ­exception being some of the business intelligence (BI) topics in Appendix J).
For example, Microsoft SQL Server 2014 is available in the Microsoft SQL Server
2014 Express Advanced package (downloadable from http://msdn.microsoft.com/en-us/
evalcenter/dn434042.aspx), and MySQL 5.6 is available in the MySQL Community Server
5.6 (downloadable from http://dev.mysql.com/downloads/mysql/.html, but if you are using a
Windows operating system, you should download and use the MySQL Installer 5.6 for
Windows from http://dev.mysql.com/downloads/windows/installer/5.6.html).
Oracle Database presents a more complex situation. The current version of Oracle
Database is Oracle Database 12c. If you have Oracle Database 12c available to you in
a computer lab or other situation where it has been installed for your use in a class or
work setting, you will be able to use it for the work in this book. Otherwise, you should
download and use the current version of Oracle Database Express Edition, which is the
Oracle Database Express Edition 11g Release 2 package (downloadable from
www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index
.html). The Oracle SQL Developer GUI utility discussed later in this chapter will work
well with both versions of Oracle Database and will allow you to complete nearly all the
exercises in this book.
Installing and using one of these DBMS products (or, at a minimum, having
Microsoft Access 2013) is a necessity for getting the most out of your study of the
material in this book—using the material in a real DBMS is an important part of your
learning process.
Of course, in order to use a DBMS product, you first have to install it and configure it on
your computer. Therefore, we discuss what you need to know to be able to successfully install
and use each DBMS product in the relevant online chapter.

492

Part 4   Multiuser Database Processing

Using the DBMS Database Administration and Database Development Utilities
Each of these DBMS products has one or more utility programs that you will use for database
administration tasks and for database development. Examples of these utilities are:
■■
■■
■■

Microsoft SQL Server 2014 uses the Microsoft SQL Server 2014 Management
Studio.
Oracle Database 12c and Oracle Database Express Edition 11g Release 2 use
Oracle SQL Developer.
MySQL 5.6 uses the MySQL Workbench.

In each online chapter, we discuss the appropriate utility programs for each DBMS product
and show you how to use them.

Creating a Database
The first step in working with a specific database in a DBMS is to actually create that database. However, this step is a bit more complicated than it might seem because each DBMS
product has different terminology for what we just called a database!
■■
■■

■■

In Microsoft SQL Server 2014, we create a database (that was easy!).
In Oracle Database 12c and Oracle Database Express Edition 11g Release 2 we may
(but it is not required that we) create a tablespace to store the tables and other objects that make up what we are referring to as a database.
In MySQL 5.6, we create a schema.

In each online chapter for the specific DBMS product, we tell you exactly what in that
DBMS product constitutes what we have been calling a database and the steps to create and
name it. In each case, we end up with a usable database named Cape_Codd for use with
the Chapter 2 SQL queries, and a second usable database named VRG for the View Ridge
Gallery database project.

Creating and Running SQL Scripts
Now that we have created the Cape_Codd and VRG databases, we need to create the table
and relationship structure of the database and then populate the tables with data. We prefer
to do this with SQL scripts, as we have discussed in Chapter 2 on SQL queries and in Chapter
7 on SQL DDL. Therefore, we discuss how to create, store, retrieve, and run SQL scripts using
one of the DBMS utilities:
■■
■■
■■

For Microsoft SQL Server 2014, we use the Microsoft SQL Server 2014
Management Studio.
For Oracle Database 12c and Oracle Database Express Edition 11g Release 2, we
use Oracle SQL Developer.
For MySQL 5.6, we use the MySQL Workbench.

Further, each DBMS product has its own variant of SQL and SQL/Persistent Stored
Modules (SQL/PSM):
■■
■■
■■

For Microsoft SQL Server 2014, we have Transact-SQL (T-SQL).
For Oracle Database 12c and Oracle Database Express Edition 11g Release 2, we
have Procedural Language/SQL (PL/SQL).
For MySQL 5.6, there is no separate variant name and we just use SQL and SQL/PSM.

We discuss each of these in the context of its parent DBMS product in the separate online
chapters.



CHAPTER 10   Managing Databases with Microsoft SQL Server 2014, Oracle Database, and MySQL 5.6

493

Reviewing the Database Structure in the DBMS GUI Utility
Besides giving us a good SQL editor to create and run SQL scripts, each DBMS product has
also built its GUI utilities with the capability to work with database objects such as tables in a
GUI mode (similar to what we do in Microsoft Access 2013). We discuss how to use specific
GUI utilities to do this:
■■
■■
■■

For Microsoft SQL Server 2014, we use the Microsoft SQL Server 2014
Management Studio.
For Oracle Database 12c and Oracle Database Express Edition 11g Release 2 we use
Oracle SQL Developer.
For MySQL 5.6, we use the MySQL Workbench.

Creating and Populating the View Ridge Gallery VRG Database Tables
Having created the VRG database and knowing how to use SQL scripts, we turn to actually
creating the VRG tables, referential integrity constraints, and indexes that form the basic
structure of the database itself. As you might expect, each DBMS product has its own variation
on exactly how this should be done. A good example of these differences is how each DBMS
product handles surrogate keys:
■■
■■
■■

In Microsoft SQL Server 2014, we use the T-SQL IDENTITY property.
For Oracle Database 12c and Oracle Database Express Edition 11g Release 2, we
use the PL/SQL SEQUENCE object.
For MySQL 5.6, we use the MySQL AUTO_INCREMENT property.

Once the database structure is created, we discuss how to populate the tables with data.
Because the VRG data as provided in Figure 7-15 contains noncontinuous surrogate key
­values, we discuss how to handle this situation when inputting data into tables.

Creating SQL Views for the View Ridge Gallery VRG Database
In Chapter 7, we discussed the use of SQL views in a database. We now show how to create
and use them in each specific DBMS.

Database Application Logic and SQL/Persistent Stored Modules (SQL/PSM)
In order to be used in an application (such as a Web site application), a database must be
accessible from that application, and several application-related problems (such as creating
and storing application variables) must be overcome. While this can be done within an application programming language such as Java; a Microsoft .NET language such as C#.NET,
C++.NET, or VB.NET; or the PHP Web scripting language (discussed in Chapter 11), we base
our main discussion on how application logic can be embedded in SQL/Persistent Stored
Modules (SQL/PSM)—user-defined functions, triggers, and stored procedures.
For each specific DBMS product, we examine and explain various SQL/PSM constructs
and features:
■■
■■
■■

Variables
Parameters
Control-of-flow statements
■■ BEGIN . . . END blocks
■■ IF . . . THEN . . . ELSE structures
■■ WHILE (looping) structures
■■ RETURN {value} statements

494

Part 4   Multiuser Database Processing

■■
■■
■■

Cursor structures and statements
SQL transaction control statements
Output statements

We then use these elements to build DBMS SQL/PSM-specific user-defined functions, stored procedures, and triggers, and we cover these topics in a depth far beyond
our ­coverage in Chapter 7. We build and run several stored procedures and triggers,
explaining both the application use of the trigger or stored procedure and additional
programming elements that are useful when creating user-defined functions, stored
­procedures, and triggers.

DBMS Concurrency Control
We discussed the concept of concurrency control in Chapter 9. As you would expect,
each DBMS product implements concurrency transaction isolation level and locking
­behavior in its own way, which we examine for each specific DBMS product in the appropriate online chapter.

DBMS Security
We discussed security in general terms in Chapter 9. For each specific DBMS product, we
summarize how those general ideas pertain to that product, examine the specific server and
database security options available, and create users with specific security privileges. We
cover these topics in a depth far beyond our coverage in Chapter 7, and when we are done
creating the needed database users for the VRG database, we are ready to use these users to
provide the needed database security for our Web database applications in Chapter 11.

DBMS Database Backup and Recovery
As explained in Chapter 9, databases and associated log files should be backed up periodically. When backups are available, it is possible to recover a failed database by restoring it
from a prior database save and applying changes in the log. Again, we cover these topics in a
depth far beyond our coverage in Chapter 7, and we examine and discuss the specific backup
and recovery features and methods of the specific DBMS.

Other DBMS Topics Not Discussed
Each online chapter covers essential topics for a specific DBMS product, but we cannot possibly cover everything about each DBMS in this book and online chapters. Therefore, we
briefly discuss some of the important topics not covered in the chapter and point you toward
information about those topics.

Choose Your DBMS Product(s)!
Please see the online chapter for the DBMS product(s) you want to install and use. Download
the appropriate online chapter, and study it, as it will be your guide to implementing the
concepts discussed in this book in a DBMS, and to really learn these concepts, you need to
actually use them in a DBMS.

CHAPTER 10   Managing Databases with Microsoft SQL Server 2014, Oracle Database, and MySQL 5.6



495

Chapter 10A: MANAGING DATABASES WITH
MICROSOFT SQL SERVER 2014
Chapter 10B: MANAGING DATABASES WITH
ORACLE DATABASE
AND
Chapter 10C: MANAGING DATABASES WITH MySQL 5.6
ARE AVAILABLE ONLINE ON THE
DATABASE PROCESSING:
FUNDAMENTALS, DESIGN, AND IMPLEMENTATION (14th EDITION)
COMPANION WEBSITE AT
www.pearsonglobaleditions.com/kroenke

Summary
There are online chapters available at the Database Processing:
Fundamentals, Design, and Implementation (14th Edition)
Companion Web site, accessible at www.pearsonglobaleditions
.com/kroenke.
These chapters have been placed online to allow us
to include more material relevant to each separate DBMS
product than the length of this book would otherwise allow.
The online materials are in PDF format and require that
you have a PDF reader installed. If you need a PDF reader,
we suggest you download and install the current version of
the free Adobe Reader from https://acrobat.adobe.com/us/en/
products/pdf-reader.html.
The material in these chapters describes the basic features and functions of Microsoft SQL Server 2014 in Chapter
10A, Oracle Database 12c and Oracle Database Express
Edition 11g Release 2 in Chapter 10B, and Oracle MySQL
5.6 in Chapter 10C. The discussion in these chapters uses
the Cape_Codd database for Chapter 2 and the View Ridge
Gallery VRG database from Chapter 7, and it parallels the discussion of SQL DDL, DML, and SQL/PSM in Chapter 7 and
the discussion of database administration tasks in Chapter 9.
Topics in each online chapter written to cover each specific DBMS product include:

■■
■■
■■
■■
■■
■■
■■
■■
■■
■■
■■
■■

Installing the DBMS
Using the DBMS Database Administration and
Database Development Utilities
Creating a Database
Creating and Running SQL Scripts
Reviewing the Database Structure in the DBMS
GUI Utility
Creating and Populating the View Ridge Gallery
VRG Database Tables
Creating SQL Views for the View Ridge Gallery
VRG Database
Database Application Logic and SQL/Persistent
Stored Modules (SQL/PSM)
DBMS Concurrency Control
DBMS Security
DBMS Database Backup and Recovery
Other DBMS Topics Not Discussed

These chapters build on the material presented in
Chapter 7, but coverage of these topics is at a depth far
beyond the Chapter 7 coverage. Please see the online
chapter for the DBMS product you want to install and
use.

496

Part 4   Multiuser Database Processing

Key Terms
locking behavior
Microsoft Access 2013
Microsoft SQL Server 2014
Microsoft SQL Server 2014 Express
Advanced
Microsoft SQL Server 2014
Management Studio
MySQL 5.6
MySQL AUTO_INCREMENT property

MySQL Community Server 5.6
MySQL Installer 5.6 for Windows
MySQL Workbench
Oracle Database Express Edition 11g
Release 2
Oracle Database 12c
Oracle SQL Developer
PL/SQL SEQUENCE object
Procedural Language/SQL (PL/SQL)

schema
stored procedures
tablespace
Transact-SQL (T-SQL)
transaction isolation level
triggers
T-SQL IDENTITY property
user-defined functions

Project Questions
10.1 Determine which DBMS product or products you will be using while working

through the material in this book.

10.2 Based on your answer to Project Question 10.1, download Chapter 10A, Chapter 10B,

and/or Chapter 10C as appropriate from the Database Processing: Fundamentals, Design,
and Implementation (14th Edition) Companion Website at www.pearsonglobaleditions.com/
kroenke.

10.3 Based on your answer to Project Question 10.1 and the discussions in Chapter 10A,

Chapter 10B, and/or Chapter 10C, download and install the DBMS software that
you will be using while working through the material in this book. When you have
­completed this Project Question, you should have available for your use a working
installation of the DBMS product or products you want to use.

Database Access
Standards
The two chapters in this section examine standards for database
application processing. We begin in Chapter 11 by discussing data­
base access standards, including ODBC, ADO.NET, and ASP.NET in
Microsoft’s .NET Framework and the Java-based JDBC and Java Server
Pages (JSP) technologies. Even though some of these standards are
no longer on the leading edge of database processing, many applications still use them, and you will likely encounter them in your career. In
fact, ODBC is making a comeback as relational DBMS products need
to ­
interconnect to BigData structured storage products (discussed in
Chapter 12), and ODBC is an established standard that can handle
the task. Chapter 11 then describes the use of the popular PHP scripting ­language to create Web pages that access the View Ridge Gallery
­database. This is followed by a discussion of the confluence of database
processing and document processing in an introduction to XML.
Chapter 12 discusses business intelligence (BI) systems, the data
warehouse and data mart databases that support BI systems, and
BigData structured storage.

5

P a r t

11
The Web Server Environment
Chapter Objectives
■■

■■
■■
■■
■■
■■

To understand the nature and characteristics of the data
environment that surrounds Internet technology database
applications
To learn the purpose, features, and facilities of ODBC
To understand the characteristics of the Microsoft .NET
Framework
To understand the nature and goals of OLE DB
To learn the characteristics and object model of ADO.NET
To understand the characteristics of JDBC and the four
types of JDBC drivers

■■
■■
■■
■■
■■

To understand the nature of JSP and know the
differences between JSP and ASP.NET
To understand HTML and PHP
To be able to construct Web database applications pages
using PHP
To understand the importance of XML
To learn the basic concepts involved in using the SQL
SELECT . . . FOR XML statement

We have now learned how to design and implement databases. Specifically, we
have used the VRG database we have designed and implemented for the View Ridge
Gallery as our example throughout most of this book. We started by c
­ reating the VRG
data model and the VRG database design in Chapter 6 and then implemented that database design in SQL Server 2014 in Chapter 7. We used it as the basis of our discussion of database redesign in Chapter 8 and of database ­administration in Chapter 9.
Databases, however, do not exist in isolation. Rather, they are created as part of
an information system and are used to store the data that the system processes to
provide information to the people who use it, as discussed at the beginning of our
work in Chapter 1.
In one way or another, today we are usually working with the World Wide
Web (WWW or W3 or Web), which is now so ubiquitous and commonly used that
­everyone takes it for granted. Application clients running in a Web browser such
as Microsoft Internet Explorer, Google Chrome, or Mozilla Firefox are the norm,
and allow users to shop online and communicate with their friends by posts on
Facebook or tweets on Twitter.
498



CHAPTER 11   The Web Server Environment

499

The WWW is not a communications network itself. Instead, the WWW runs on
the Internet, a system of interconnected smaller networks that now spans the Earth
and allows computer communication worldwide.
We no longer need a computer to use the Web. In addition to using the Web on
their computers, people are using a mobile phone (or cell phone) over a ­cellular
network provided by vendors such as Verizon, T-Mobile, AT&T, and Sprint. The
emerging smartphone makes use of the data packages available from cellular
­providers to access the WWW, making smartphones very portable computers.
Another emerging form factor is the tablet, of which the Apple iPad is the best
example (although many other tablets running the Google Android operating system (OS) are also available). Tablets connecting to the Internet provide another link
in the interconnected life style we are living today.
Figure 11-1 illustrates how people use these devices today, in what is technically
known as client server architecture. Users actually want some sort of s
­ ervice,
such as shopping online or communicating on Facebook. To get this service, a user
has a hardware device (computer, smartphone, or tablet) that runs a software c
­ lient
application that provides the user with an interface for a desired service. A Web
browser is often the client for a service such as Facebook or Twitter (a smartphone
app is also a client for these services). A service is provided by a special computer
called a server (because it provide the service). For example, Twitter uses servers
to receive, store, and broadcast tweets. The client and the server communicate
over the Internet or a cellular data network (which itself will connect to the Internet
at some point). Internet hardware such as routers running networking software are
responsible for the connections between the client and the server.

Figure 11-1

DEVICES
running
SERVICE CLIENT
software

Client Server Architecture

USERS

INTERNET HARDWARE
SERVERS
running
running
DATABASES
NETWORKING
SERVICE SERVER
software
software

500

Part 5   Database Access Standards

And supporting all the client server applications are databases. Every application needs to store, update, read, and delete data, and, as we have learned, that is
the purpose of a database. Databases do not exist for their own sake—they exist to
be used by applications needing the data they hold and maintain.
In this chapter, we will discuss and demonstrate exactly how databases are
used to support the services that users want. This chapter begins by discussing
some traditional standard interfaces and some current tools for accessing database
servers. ODBC, or the Open Database Connectivity standard, was developed in the
early 1990s to provide a product-independent interface to relational and other tabular data. Today, it is finding new life because of the new nonrelational databases being developed to deal with the Big Data environment (which we will discuss in detail
in Chapter 12 and Appendix K—Big Data). In the mid-1990s, Microsoft announced
OLE DB, which is an object-oriented interface that encapsulates data-server functionality. Microsoft then developed Active Data Objects (ADO), which is a set of
objects for utilizing OLE DB that is designed for use by any language, including
VBScript and JScript/JavaScript. This technology was used in Active Server Pages
(ASP), which were the basis of Web database applications. In 2002, Microsoft introduced the .NET Framework, which included ADO.NET (the successor to ADO) and
ASP.NET (the successor to ASP) components. Today, the .NET Framework is the
basis for all application development using Microsoft technology.
As an alternative to the Microsoft technologies, Sun Microsystems developed
the Java platform, which includes the Java programming language, Java Database
Connectivity (JDBC), and Java Server Pages (JSP), in the 1990s. Sun Microsystems
was purchased by Oracle Corporation in 2010, and the Java platform is now part of
the Oracle family.
Although the .NET and Java technologies are important development platforms,
additional technologies have been developed by other companies and open source
projects. We will use two of these independently developed tools in this chapter: the
NetBeans integrated development environment (IDE) and the PHP scripting language.
This chapter also considers one of the most important recent developments in information systems technology. It discusses the confluence of two information technology
subject areas: database processing and document processing. For more than 20 years,
these two subject areas developed independently of one another. With the advent of
the Internet, however, they crashed together in what some industry pundits called a
technology train wreck. The result is still being sorted out, with new products, product
features, technology standards, and development practices emerging every month.

A Web Database Application for the View Ridge Gallery
Now that we have created the VRG database, we will use it in this chapter as the basis for
developing a Web database application for the View Ridge Gallery. We will call this Web
­database application the View Ridge Gallery Information System (VRGIS), and the VRGIS
will provide both reporting and data input capabilities for the gallery. A screen shot of the
VRGIS was used in Figure 6-35 to illustrate our introduction of the View Ridge Gallery. But
before we build the VRGIS, we need to understand the underlying basis and process for
­developing Web database applications.



501

CHAPTER 11   The Web Server Environment

The Web Database Processing Environment
The environment in which today’s Web database applications reside is rich and complicated.
As shown in Figure 11-2, users use Web browsers on their computers to request Web pages
from Web servers, which in turn request information from database servers, which use a
DBMS to obtain the data from their databases. Various programming languages are used in
the process of creating the Web page code that is returned to the Web browser, which formats
the Web page and displays it for the user. The final Web page coded may include:
■■
■■
■■

Scripting language code, such as JavaScript, which runs on the user’s computer.
Code generated by Web server programming languages, such as PHP, which
­controls the code content returned to the Web browser.
Output from databases generated by Web servers sending requests for DBMS
­operations using SQL and SQL/PSM.

While we will not discuss scripting languages in this text, you are undoubtedly familiar
with their actions. A very familiar example is the “Does not match” message you see every
time a Web form requires you to reenter some data such as an email address or new password
for validation and you don’t retype it exactly. This type of error checking is performed locally
on your computer by a Web page scripting language such as JavaScript.
We will discuss the interaction between the Web server and the DBMS, In a Web-based
database processing environment, if the Web server and the DBMS can run on the same
computer, the system has two-tier architecture. (One tier is for the Web browsers, and one
is for the Web server/DBMS computer.) Alternatively, the Web server and DBMS can run on
different computers, in which case the system has three-tier architecture, as illustrated in
Figure 11-2. High-performance applications might use many Web server computers, and in
some systems several computers can run the DBMS as well. In the latter case, if the DBMS
computers are processing the same databases, the system is referred to as a distributed database.
Distributed databases are discussed later in this chapter.
As shown in Figure 11-3, a typical Web server needs to create Web pages that involve
data from dozens of different sources, each with different data types. So far in this text, we
have considered only relational databases, but as you can see from this figure, there are many
other data types as well.
Consider the problems that the developer of Web server applications has when integrating these data. The developer may need to connect to:
■■
■■
■■
■■

A relational database created in Microsoft SQL Server or Oracle Database.
A nonrelational database, such as Apache Cassandra or Neo Technology’s Neo4j.
File-based data, such as found in spreadsheets such as Microsoft Excel.
Email directories.

Each one of these products has a different programming interface that the developer must
learn. Further, these products evolve; thus, new features and functions will be added over time
that will increase the developer’s challenge.

Figure 11-2
Three-Tier Architecture

COMPUTERS
running
WEB CLIENT software

SERVERS
running
WEB SERVER software

Web Page Request

Web Browser
Scripting Languages:
JavaScript

SERVERS
running
DBMS software

Database Request

Web Page
Programing Languages:
PHP

DATABASES

Data Request

DBMS
Database Languages:
SQL and SQL/PSM