51
Databases Databases Chapter 11 Chapter 11

Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents Section A: File and Database Concepts Section B: Data Management Tools Section

Embed Size (px)

Citation preview

Page 1: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

DatabasesDatabases

Chapter 11Chapter 11

Page 2: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 2

11 Chapter Contents

Section A: File and Database Concepts Section B: Data Management Tools Section C: Database Design Section D: SQL Section E: Database Security

Page 3: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 3

11SECTION A

File and Database ConceptsFile and Database Concepts Database Basics Database Models

Page 4: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 4

11 Database Basics A database is a collection

of information– Typically stored as computer

files

The tasks associated with creating, maintaining, and accessing the information in databases are referred to as data managementdata management, file management, or database management

Page 5: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 5

11 Database Basics

Databases can be used in a variety of ways– Collect and store data– Update data– Organize and

output data– Distribute data– Find data– Analyze data

Page 6: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 6

11 Database Basics

Data miningData mining refers to the process of analyzing existing information in databases to discoverdiscover previously unknown and potentially useful informationuseful information, including relationships and patterns– Data warehouse– Predictive analytics

Page 7: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 8

11 Database Models

An unstructured fileunstructured file has a unique structure A structured filestructured file uses a uniform format to

store data The underlying structure

of a database is referred to as a database modelmodel

Page 8: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 9

11 Database Models

The simplest model for storing data is a flat flat filefile that consists of a single, two-dimensional two-dimensional tabletable of data elements

Records can be displayed as rows in a table or as forms.

Page 9: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 10

11 Database Models

A fieldfield contains the smallest unit of meaningful information

Each field has a unique field namefield name Variable-lengthlength field vs. fixed-length field

Page 10: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 11

11 Database Models

A recordrecord is a related collectionrelated collection of data fields The templatetemplate (blank form) for a record is

referred to as a record type A record that contains data is referred to as a

record occurrenceoccurrence

Page 11: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 12

11 Database Models

A relationshiprelationship is an associationassociation between data that is stored in different record types– One-to-many– Many-to-many– One-to-one

Page 12: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 14

11 Database Models

A hierarchical databasehierarchical database arranges record types in a hierarchy

Page 13: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 15

11 Database Models

The network databasenetwork database model allows many-to-many relationships in addition to one-to-many relationship

Page 14: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 16

11 Database Models

A relational databaserelational database stores data in a collection of related tablesrelated tables

Much more flexibleflexible than hierarchical or network models.

Page 15: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 17

11 Database Models

A (multimulti)dimensional databasedimensional database organizes relationships over three or more dimensions

Easy to maintain.

Data is stored in a structure related to its use.

Used primarily for data analysis and decision support systems.

Page 16: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 18

11 Database Models

An object (object-oriented) databaseobject (object-oriented) database stores data as objects, which can be grouped into classes and defined by attributes and methods

Page 17: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 19

11 Database Models An object-relational object-relational

databasedatabase is used to describe a variety of technologies that combine object-oriented and relational concepts

Page 18: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 20

11SECTION B

Data Management ToolsData Management Tools Data Management Software Database Management Systems Databases and the Web XML

Page 19: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 21

11 Data Management Software

Microsoft Word Microsoft Word allows you to create a “flat” table of information, such as a mailing list, which you can edit, sort, search, and print. In addition, you can merge data from the table with a template letter to create form letters, mailing labels, and envelopes.

Page 20: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 22

11 Data Management Software

MS ExcelMS Excel

Page 21: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 23

11 Data Management Software

It is possible to enter data as ASCII text file Custom data management software Data dependenceData dependence vs. data independencedata independence

Page 22: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 24

11 Database Management Systems

Software packages Software packages designed to manage data stored in a database– XML DBMS (primarily for use on the Web)– OODBMS (object-oriented DBMS)– RDBMS (Relational DDMS - often include tools

to deal with XML and object-oriented data)

Page 23: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 25

11 Database Management Systems

An entry-level DBMS,like Microsoft AccessMicrosoft Access,usually includes all thetools you need to manipulate data in a database.

Page 24: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 26

11 Database Management Systems

Database client softwareDatabase client software allows a remote computer or network workstation to access data in a remote database (database server)

Page 25: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 27

11 Database Management Systems

Multiple users can interact with the same database

Page 26: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 28

11 Databases and the Web

The Web provides opportunities and challenges for accessing databases– StaticStatic Web publishing (read-only snapshot of

data)– DynamicDynamic Web publishing (script-driven, on-the-fly

view of data)• Server-side program

Page 27: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 30

11 Databases and the Web

Page 28: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 31

11 Databases and the Web FormsForms can

collect datacollect data for database update,as well as specifications for a queryquery– XFormsXForms: an

alternative to HTML forms

Page 29: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 32

11 Databases and the Web

Several tools are available to help create server-side programs

ASP: Active Server Pages (Microsoft)CGI: Common Gateway Interface (standard)PHP: Hypertext Preprocessor

Page 30: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 33

11 XML Documents

Markup languageMarkup language allows field tags, data, and tables to be incorporated into a Web document

Page 31: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 34

11 XML Documents Used to specify a standard structurestandard structure of fields

and records Data in an XML document is searchable searchable via

XML query engines (XPath, XQuery) XML is portableportable, but not optimized for many

common database operations– Consider storing data in a relational database,

managing it with RDBMS software, and generating XML documents for exchanging data over the Web

Page 32: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 35

11SECTION C

Database DesignDatabase Design Defining Fields Normalization Organizing Records Designing the Interface Designing Report Templates Loading Data

Page 33: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 36

11 Defining Fields The term database structuredatabase structure refers to the

arrangement of fields, tables, and relationships in a database

Example: Storing last names and first names in separate fields

Use a primary keyprimary key field to make each record unique unique (e.g., your student id #)

Use appropriate data types for each field (e.g., store numbers as numbers, not text)

Page 34: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 37

11 Defining Field

Some Basic Data TypesData Types:

Page 35: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 38

11 Defining Fields A computed (calculated, derived) fieldcomputed (calculated, derived) field is a

calculation that a DBMS performs during processing and stores temporarily

Uppercase and lowercase are not always treated the same– Case sensitive database

Field formats show what the data is supposed to look like when it’s entered

Field validation rulesField validation rules are used to filter data

Page 36: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 39

11 Normalization

Process that helps save storage space and increase processing efficiency– Reduces data redundancyReduces data redundancy

Notice that in this example, there is no need to carry complete customer info in each record for every order.

Page 37: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 40

11 Organizing Records Records can be organized in different ways,

depending on use Sorting

– A table’s sort ordersort order refers to the order in which records are stored in the database

– The sort key sort key is the field that is used to determine the sort order

Indexing– Refers to an index numberindex number for the record for each sort

key– Similar to the index in a book (“where do I find….?”)

Page 38: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 41

11 Organizing Records

When indexed by date, the index file contains a list of keys and the record number (R#) that contains more information about the album released on that date.

Page 39: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 42

11 Designing the Interface

Arrange fields in a logical orderlogical order Provide visual cluesvisual clues to the entry areas Entry areas should appear in a consistent

positionposition relative to their labels Provide a quickquick way to move through the

fields in order

Page 40: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 43

11 Designing the Interface

Use scrollingscrolling or create multiple screens, if necessary

Provide buttonsbuttons or other easy-to-use controls for navigating through records

Supply on-screen instructionsinstructions

Page 41: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 44

11 Designing the Interface

Page 42: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 45

11 Designing Report Templates

Report generators are used to specify the content and format for a database report

A report template contains the outline or general specifications for a report

Page 43: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 48

11SECTION D

SQLSQL SQL Basics Adding Records Searching for Information Updating Fields Joining Tables

Page 44: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 49

11 SQL Basics

Intermediary between the database client software and the database itself– Query language

SQL: Structured Structured Query LanguageQuery Language

Page 45: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 50

11 SQL Basics

Some Basic SQL Commands:

Page 46: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 51

11 Adding Records

Page 47: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 52

11 Searching for Information

SELECT AlbumTitle, AlbumCover FROM Albums

WHERE ArtistName = ‘Jefferson Airplane’

The AND, OR, and NOT Boolean operatorsBoolean operators are used to perform complex SQL searches

The use of parenthesesparentheses indicates the part of the query to perform first (specifies precedence of operations)

Page 48: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 53

11 Updating Fields

UPDATE Albums

SET InStock = InStock – 1

WHERE AlbumTitle = ‘G.I. Blues’

Global updatesGlobal updates change the data in more than one record at a time– Works only for records with similar characteristics

Page 49: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 54

11 Joining Tables

Joining tables in SQL allows you to create relationships between tablesrelationships between tables

Page 50: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11: Databases 55

11 Joining Tables

SELECT Albums.AlbumTitle,Albums.AlbumCover,Albums.DiscountPrice,Tracks.TrackTitleFROM Albums JOIN Tracks onAlbums.Cat# =Tracks.Cat#WHERE Album.Cat# = ‘LPM-2256’

Page 51: Databases Chapter 11. 11 Chapter 11: Databases2 Chapter Contents  Section A: File and Database Concepts  Section B: Data Management Tools  Section

Chapter 11 CompleteChapter 11 Complete

DatabasesDatabases