Download database

Document related concepts

IMDb wikipedia , lookup

Microsoft Access wikipedia , lookup

Oracle Database wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Concurrency control wikipedia , lookup

Ingres (database) wikipedia , lookup

Functional Database Model wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Database wikipedia , lookup

ContactPoint wikipedia , lookup

Healthcare Cost and Utilization Project wikipedia , lookup

Relational model wikipedia , lookup

Clusterpoint wikipedia , lookup

Database model wikipedia , lookup

Transcript
信息处理技术
Chapter10:
4: Computer,
1:
File
Management,
Internet,Virus
Chapter
Databases
Protection,
Web,
and E-Mail
and Backup
Basics
1
2
Chapter 10 Preview
After this chapter, you should be able to:
– Define basic database terminology, such
as fields, records, record types, and
cardinality
– Describe the characteristics of hierarchical,
network, relational, and object-oriented
databases
– Explain the capabilities of various data
management tools, such as commercial
applications, word processing software,
spreadsheet software, file management
software, and database management
Chapter 10: Databases
3
Chapter 10 Preview
– Describe various ways to provide access to
databases via the Web
– Explain how to design an effective
relational database
– Use your knowledge of SQL queries to
describe how to add records, delete
records, search for information, update
fields, and simultaneously access data
from multiple tables
Chapter 10: Databases
4
Chapter 10 Outline
• Section A
– File and Database Concepts
• Section B
– Data Management Tools
• Section C
– Database Design
• Section D
– SQL
Chapter 10: Databases
5
Chapter 10
Databases
Section A: File and Database Concepts
文件及数据库的概念
Computer Concepts 8th Edition
Databases and Structured
Files: What is a database?
• A database is a collection of information
• Databases are typically stored as
computer files
• A structured file uses a uniform format
to store data for each person or thing in
the file
Chapter 10: Databases
Page 514
7
Fields: What is the basic
element of a structured file?
• A field contains the smallest unit of
meaningful information
• Each field has a unique field name that
describes its contents
• A field can be either variable length or
fixed length
Chapter 10: Databases
Page 514
8
Records: What is a record?
• A record refers to
a collection of
data for someone
or something
• A record is made
of fields of
individual pieces
of data for each
person or thing
Chapter 10: Databases
Page 515
9
Relationships and Cardinality:
How do record types pertain to
files and databases?
• A data file that contains only one record
type is often referred to as a flat file
• In contrast, a database can contain a
variety of different record types
Chapter 10: Databases
Page 517
10
What are relationships?
• An association between data that’s stored in
different record types (a field in one table can
refer to a record in another Table)
• One important aspect of the relationship
between record types is cardinality
• Cardinality refers to the number of associations
that can exist between two record types
– A particular order cannot be placed jointly by two
customers
• When one record is related to many records, the
relationship is referred to as a one-to-many
relationship
Chapter 10: Databases
Page 517
11
What are relationships?
???
Chapter 10: Databases
Page 518
12
What’s a relational database?
• Stores data in a collection of related
tables
• Each table (also called a “relation”) is a
sequence, or list, of records.
• All of the records in a table are of the
same record type
Not
Relationship
Chapter 10: Databases
Page 520
13
What’s a relational database?
Chapter 10: Databases
Page 520
14
What’s an object-oriented
database?
• Stores data as objects, which can be grouped
into object classes, and defined by attributes
and method
• A class specifies the attributes and methods
that are shared by all objects in a class
• A class attribute is equivalent to a field, and
contains the smallest unit of data
• A method is any behavior that the object is
capable of performing
Chapter 10: Databases
Page 521
15
What’s an object-oriented
database?
Chapter 10: Databases
Page 521
16
Chapter 10
Databases
Section B: Data Management Tools
数据管理工具
Computer Concepts 8th Edition
Data Management Software:
Are simple data management
tools available?
• The simplest tools for managing data are
software packages designed for a specific
data management task
• To use one of these tools, you just enter
your data
• The software provides menus that allow
you to manipulate your data after it is
entered
Chapter 10: Databases
Page 522
18
How about a simple, generic tool
that allows me to define a file
structure?
Chapter 10: Databases
Page 522
19
How about a simple, generic tool
that allows me to define a file
structure?
Chapter 10: Databases
Page 523
20
Database Management Systems:
What kinds of tools are specifically
designed for creating and
manipulating databases?
• DBMS (database management system)
refers to software that is designed to
manage data stored in a database
• An XML DBMS, for example, is optimized for
handling data that exists in XML format
• An OODBMS (object-oriented database
management system) is optimized for the
object-oriented database model
Chapter 10: Databases
Page 525
21
What kinds of tools are
specifically designed for creating
and manipulating databases?
• An RDBMS (relational database
management system) allows you to
create, update, and administer a
relational database
• Today’s most popular RDBMS software
also provides capability to handle object
classes and XML data
Chapter 10: Databases
Page 525
22
What kinds of tools are
specifically designed for creating
and manipulating databases?
Chapter 10: Databases
Page 525
23
Databases and the Web: Is it
possible to access a database
over the Web?
• The Web provides both opportunities and
challenges for accessing the information in a
database
• The Web provides an opportunity for many people
to gain access to data from many locations
• Web access is constrained by the stateless nature
of HTTP
• Web access to hierarchical, network, relational,
and object-oriented databases is
Chapter 10: Databases
Page 527
24
What’s the simplest way to
provide Web-based access to a
database?
Chapter 10: Databases
Page 527
25
What if I want to provide
access to current data?
Chapter 10: Databases
Page 528
26
Is it possible to add and update
database records via the Web?
Chapter 10: Databases
Page 529
27
How do I create server-side
programs?
• Several tools, including ASP, CGI, and PHP
help you create server-side programs
• ASP (Active Server Pages) technology can be
used to generate an HTML document that
contains scripts
• Scripts are small embedded programs that can
be designed to get user input, run queries, and
display query results
• CGI (Common Gateway Interface) provides a
non-proprietary way to create HTML pages
based on data in a database
Chapter 10: Databases
Page 529
28
How do I create server-side
programs?
Chapter 10: Databases
Page 530
29
XML Documents: How does XML
relate to the Web and
databases?
• XML is a markup language that allows
field tags, data, and tables to be
incorporated into a Web document
• HTML documents contain lots of
information
• XML provides tags that can be embedded
in an XML document to put data in context
Chapter 10: Databases
Page 530
30
How is XML typically used
today?
• XML’s most positive contributions to data
management is the ability to add context to the
information contained in a widely diverse pool of
documents on the Web
• An XML document can also contain structured
data organized into records and fields
• Storing data in an XML document provides
several advantages
– It is “portable”
Chapter 10: Databases
Page 531
31
How is XML typically used
today?
Chapter 10: Databases
Page 531
32
Chapter 10
Databases
Section C: Database Design
数据库设计
Computer Concepts 8th Edition
Defining Fields: How does a
database designer know what
data to store?
• The first step in designing a relational
database is to determine what data must be
collected and stored
• A database designer might begin by listing
available data, as well as any additional data
that is necessary to produce on-screen output
or printed reports
• The next step is to organize that data into
fields
Chapter 10: Databases
Page 533
34
Why are last names stored in a
different field than first
names?
• The treatment of first and last names
illustrates the concept of breaking data
into fields
• With the entire name in one field, the
database would not be able to access
individual parts of the name
Chapter 10: Databases
Page 533
35
What makes each record
unique?
• A computer must have some way to
differentiate between records
• A primary key is a field that contains
data unique to a record
• Examples: SSN, RUID, not lastname
Chapter 10: Databases
Page 534
36
How does a database designer
know what data types to use?
• The data that can be entered into a field
depends on the field’s data type
• From a technical perspective, a data type
specifies the way data is represented on the
disk and in RAM
• From a user perspective, the data type
determines the way that data can be
manipulated, e.g. addition
• The two most common data types are numeric
and character
Chapter 10: Databases
Page 534
37
How does a database designer
know what data types to use?
•
•
•
•
•
•
•
Real, e.g. 3.14, $5.99
Integer, e.g. 0, 1, 2345
Date, e.g. 11/10/2005
Text, e.g. Gilbert, Grape (fixed length)
Logical, e.g. yes/no, on/off, opened/closed
Memo, Text with no fixed length
BLOB, binary files, e.g. MSWord.exe,
itec100.xls, me.gif
• Hyperlink, e.g. www.radford.edu/~kstevens2
Chapter 10: Databases
Page 534
38
How does a database handle
computations?
• A computed field is a calculation that a
DBMS performs during processing
• An efficiently designed database uses
computed fields whenever possible
• Example: MSRP, DiscountPrice,
(Savings)
Chapter 10: Databases
Page 535
39
Can a database designer
prevent people from entering
inaccurate data?
• The information supplied by reports and
processing routines is only as accurate as the
information in the database, GIGO
• Data entry errors can compromise the accuracy
and validity of a database
• Most DBMS tools that the database designer can
use to prevent some, but not all, data entry
errors, e.g. require a decimal point, 3.00, or must
be numeric
• In a case sensitive database, uppercase letters
are not equivalent to their lowercase
counterparts, e.g. Jewel, jewel, JEWEL
Chapter 10: Databases
Page 536
40
Can a database designer
prevent people from entering
inaccurate data?
• Field validation rule, range $0.00 $100.00
• Pick from a list
• Look up routine
• Field format
Chapter 10: Databases
Page 536
41
Normalization: How does a
database designer group fields
into tables?
• Normalization helps the database designer
create a database structure that can save
storage space and increase processing
efficiency
• The goal of normalization is to minimize data
redundancy
• The first step to grouping fields is to get an idea
of the “big picture” of the data
• Groupings correspond to the physical items
(nouns), or entities, that are tracked in the
database
Chapter 10: Databases
Page 537
42
How does a database
designer group fields into
tables?
• This data redundancy not only requires
extra storage space, but also may lead to
storing inconsistent or inaccurate data
• The solution is to create separate tables
• If the designer provides fields for ordering
ten items, the database cannot handle
large orders for more than ten
Chapter 10: Databases
Page 538
43
How does a database
designer group fields into
tables?
Chapter 10: Databases
Page 543
44
How does a database
designer group fields into
tables?
Chapter 10: Databases
Page 538
45
How does a database
designer group fields into
tables?
• If a customer orders fewer than ten, space
is wasted by having empty fields in each
record
• A one-to-many relationship exists between
an order and the ordered items
• The database designer should separate
the data into two tables such as Orders
and OrderDetails
Chapter 10: Databases
Page 538
46
How does a database
designer group fields into
tables?
Chapter 10: Databases
Page 538
47
What happens when the data
in a table is sorted?
• A table’s sort order is the order in which records
are stored on disk
• Sorted tables typically produce faster queries
and updates
• Queries and updates within an unsorted
database are slow
• A table’s sort key is one or more fields that are
used to specify where new records are inserted
in a table
• A table can have only one sort key at a time, but
the sort key can be changed, which is slow
Chapter 10: Databases
Page 539
48
How is indexing different
from sorting?
Figure 10-36
• A database index contains a list of keys, and
each key provides a pointer to the record that
contains the rest of the fields related to that key
• An index has no bearing on the physical
sequence of records on disk
• A table can have multiple indexes, but only one
sort order
• Database tables should be indexed by any field
or fields that are commonly used as search fields
• The database designer typically creates indexes
at the time the database structure is designed
Chapter 10: Databases
Page 539
49
What makes a good interface?
•
•
•
•
•
Arrange fields in a logical order
Provide visual clues, e.g. color
Provide easy-to-use controls, e.g. buttons, lists
Scroll only if absolutely necessary
Provide instructions/help, e.g. Help System,
ToolTips
• Provide appropriate Field Labels
Chapter 10: Databases
Page 540
50
Designing Report Templates:
How can I display or print data
as a formatted report?
• A report generator is a software tool that provides
the ability to create report templates for a database
• A report template contains the outline or general
specifications for a report
• The template does not, however, contain data from
the database
• Data is merged into the template when you actually
run a report
• When you actually produce a report, it is based on
the data currently contained in the database table
Chapter 10: Databases
Page 542
51
How does the database
designer create effective
report templates?
• The database designer can create
templates for reports that effectively
present information by observing the
following guidelines:
– Supply only the information required
– Present information in a usable format
– Information should be timely
Chapter 10: Databases
Page 543
52
How does the database
designer create effective
report templates?
– Information should be presented in a clear,
unambiguous format, and include
necessary titles, page numbers, dates,
labels, and column headings
– Present information in the format most
appropriate for the audience
Chapter 10: Databases
Page 543
53
How is data loaded into the
database tables?
• A conversion routine converts the data
from its current format into a format
that can be automatically incorporated
into the new database
• An import routine brings data into a
database
• An export routine copies data out of a
software package, and into the
database
Chapter 10: Databases
Page 544
54
Chapter 10
Databases
Section D: SQL
数据库查询语言-SQL
Computer Concepts 8th Edition
How does a query language
work?
• Structured Query Language, SQL
• Work behind the scenes as an between
the client software provided to users, and
the database itself
• Intermediary database client software
collects your input, then converts it into an
SQL query
• An SQL query operates directly on the
database to carry out your instructions
Chapter 10: Databases
Page 546
56
How does a query language
like SQL work?
SQL
Query
Chapter 10: Databases
Page 546
57
What does a simple SQL
query look like?
• An SQL query is a sequence of words, much like a
sentence
– SELECT TrackTitle FROM Tracks WHERE
TrackTitle = ‘Fly Away’
• The SQL query language provides a collection of
special command words called SQL keywords
• Many SQL queries can be divided into three simple
elements that specify an action, the name of a
database table, and a set of parameters
Chapter 10: Databases
Page 547
58
How does SQL specify the
action that I want carried out
in the database?
Chapter 10: Databases
Page 547
59
How does SQL specify which
table to use?
• SQL keywords such as USE, FROM, or
INTO can be used to construct a clause
specifying the table that you want to
access.
• The clause consists of the keyword
followed by the name of the table
Chapter 10: Databases
Page 547
60
How does SQL specify
parameters?
• The term parameter refers to the
detailed specifications for a command
• Keywords such as WHERE usually
begin an SQL clause containing the
parameters for a command
Chapter 10: Databases
Page 548
61
Adding Records: How are
records added to a
database?
• The client software that you use collects
the data that you enter in the form and
generates an SQL statement using the
INSERT command, which adds your
data to the database
Chapter 10: Databases
Page 548
62
Searching for Information:
How do SQL queries carry
out searches?
• One of the most common database
operations is to query for a particular
record or group of records using the
SELECT command
Chapter 10: Databases
Page 549
63
Can SQL perform complex
searches?
• SQL uses search operators to form
complex queries
• Because search operators were
originally the idea of mathematician
George Boole, they are also referred to
as Boolean operators
Chapter 10: Databases
Page 549
64
How does AND work in an
SQL query?
• AND (sometimes indicated by a + sign) is
used when you want to retrieve records that
meet more than one criteria
• The AND operator specifies that both of the
search criteria must be true for the record to
be selected
• SELECT CDName FROM CompactDisks
WHERE ArtistName = ‘Beyonce’
AND DiscountPrice < 10.00
Chapter 10: Databases
Page 549
65
How does OR differ from
AND?
• Inclusive OR
Exclusive OR
– SELECT CDName FROM CompactDisks
WHERE (ArtistName = ‘Beyonce’
OR ArtistName = ’Destiny’s Child’)
AND DiscountPrice <10.00
• Note the use of parentheses around the
OR clause
Chapter 10: Databases
Page 550
66
How does NOT work in an
SQL query?
• The NOT operator can be used to specify
a not-equal relationship
– SELECT CDName FROM CompactDisks
WHERE NOT(ArtistName = ‘Beyonce’)
• Sometimes NOT relationships are
specified using a not-equal operator, like
<> or !=, depending on the specifications
of the query language
– SELECT CDName FROM CompactDisks
WHERE ArtistName <> ‘Beyonce’
Chapter 10: Databases
Page 550
67
Updating Fields: Can I change
the contents of a record?
• You can change records in a database
only if you have the rights to do so
– UPDATE CompactDisks
SET QtyInStock = QtyInStock – 1
WHERE CDName = ‘Dangerously in Love’
Chapter 10: Databases
Page 551
68
Is it possible to update a
group of records?
• SQL can perform a global update that changes
the data in more than one record at a time
• It would be easier to change all of the records
with a single command
– UPDATE CompactDisks
SET DiscountPrice = 9.95
WHERE ArtistName = ‘The Rolling Stones’
• The UPDATE command means that you want to
change the data in some or all of the records
Chapter 10: Databases
Page 551
69
Joining Tables: How is data
retrieved from more than one
table at a time?
• Creating a relationship between tables is
referred to as joining tables
• To take advantage of the relationship
between two tables, you first have to join
the tables
• The SQL JOIN command allows you to
temporarily join and simultaneously access
the data in more than one table
Chapter 10: Databases
Page 552
70
How is data retrieved from
more than one table at a
time?
Chapter 10: Databases
Page 552
71
How extensive is SQL?
• Very extensive and powerful language
• Can be used to
– Manipulate data
– Create databases, tables, and reports
Chapter 10: Databases
Page 553
72
Conclusion
You should now be able to:
– Define basic database terminology, such
as fields, records, record types, and
cardinality
– Describe the characteristics of hierarchical,
network, relational, and object-oriented
databases
– Explain the capabilities of various data
management tools, such as commercial
applications, word processing software,
spreadsheet software, file management
software, and database management
Chapter 10: Databases
73
Conclusion
– Describe various ways to provide access to
databases via the Web
– Explain how to design an effective
relational database
– Use your knowledge of SQL queries to
describe how to add records, delete
records, search for information, update
fields, and simultaneously access data
from multiple tables
Chapter 10: Databases
74