29
Stephen C. Hayne Database System Database System Components Components The Database and the DBMS The Database and the DBMS

Stephen C. Hayne 1 Database System Components The Database and the DBMS

Embed Size (px)

Citation preview

Page 1: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 1

Database System ComponentsDatabase System Components

The Database and the DBMSThe Database and the DBMS

Page 2: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 2

A Model of the Database A Model of the Database Processing SystemProcessing System

Hardware Programs Data Procedures People

Machine Human

Bridge

Instructions

Actors

Page 3: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 3

Database System ComponentsDatabase System Components

Page 4: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 4

User DataUser Data

Data aboutData about– Entities or objects Entities or objects

» employees, departments, products....employees, departments, products....» students, courses, professorsstudents, courses, professors

– Attributes Attributes » SS#, name, address, salary, departmentSS#, name, address, salary, department

– Relationships (bi-directional) between entities or objectsRelationships (bi-directional) between entities or objects» Employees Employees assigned to assigned to Departments.Departments.» Departments Departments are assignedare assigned Employees. Employees.» Students Students take take Courses.Courses.» Courses Courses are taken byare taken by Students. Students.

Page 5: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 5

Users’ DataUsers’ Data

For relational databases, tables with rows For relational databases, tables with rows and columns representing unique records and columns representing unique records and attributesand attributes

Not all tables are equally desirable: What is Not all tables are equally desirable: What is the problem with this?the problem with this?

Movie Rating Star

Saving Private Ryan G Tom Hanks

Saving Private Ryan G Matt Damon

Titanic R Kate Winslet

Titanic R Leonardo Di Caprio

Page 6: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 6

Relationships Between EntitiesRelationships Between Entities

CardinalityCardinality– the number of entities of each type that may the number of entities of each type that may

participate in the relationshipparticipate in the relationship– may be may be

» 1:1 (one-to-one)1:1 (one-to-one)

» 1:M (one-to-many)1:M (one-to-many)

» M:N (many-to-many)M:N (many-to-many)

– to determine cardinality, ask:to determine cardinality, ask:» for each A, how many B’s may be related?for each A, how many B’s may be related?

» for each B, how many A’s may be related?for each B, how many A’s may be related?

Page 7: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 7

Minimum & Maximum CardinalityMinimum & Maximum Cardinality

For each A, what is the minimum and maximum For each A, what is the minimum and maximum number of related B’s. number of related B’s.

For each B, what is the minimum and maximum For each B, what is the minimum and maximum number of related A’s. number of related A’s.

If the minimum is zeroIf the minimum is zero– The relationship is “The relationship is “optionaloptional.”.”

– The entity may or may not (The entity may or may not (sometimessometimes) participates ) participates

One or more One or more – The relationship is “mandatory.The relationship is “mandatory.

The entity must (The entity must (alwaysalways) participate. ) participate.

Page 8: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 8

Relationship ExamplesRelationship Examples

Business RulesBusiness Rules 1 : 1 (one-to-one)1 : 1 (one-to-one)

– Each faculty member is Each faculty member is alwaysalways assigned to assigned to oneone office. office.

– Each office is Each office is sometimessometimes assigned to assigned to oneone faculty member. faculty member. 1 : M (one-to-many)1 : M (one-to-many)

– Each employee is Each employee is alwaysalways assigned to assigned to one one department.department.

– Each department is Each department is alwaysalways assigned assigned manymany employees. employees. M : N (many-to-many)M : N (many-to-many)

– Each student Each student alwaysalways takes takes manymany courses. courses.

– Each course is Each course is sometimessometimes taken by taken by manymany students students

Page 9: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 9

What is the cardinality between...What is the cardinality between...

Cities and zip codes?Cities and zip codes?– Each city Each city ?? has has ?? zip codes. zip codes.

– Each zip code Each zip code ?? corresponds to only corresponds to only ?? city. city.

===> 1:M===> 1:M

People and phone numbers?People and phone numbers?– Each person Each person ?? has has ?? phone numbers. phone numbers.

– Each phone number Each phone number ?? belongs to ? persons. belongs to ? persons.

===> M:N===> M:N

Page 10: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 10

Four Data “Models”Four Data “Models”

HierarchicalHierarchical NetworkNetwork RelationalRelational Object OrientedObject Oriented

Page 11: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 11

HierarchicalHierarchical

Support 1:1 and 1:M RelationshipsSupport 1:1 and 1:M Relationships Parent - Child ViewpointParent - Child Viewpoint Parent (Owner) record has one or more Parent (Owner) record has one or more

children (Members)children (Members)– Customer has one checking accountCustomer has one checking account– Checking account has many transactionsChecking account has many transactions

Each child (member) has only one parent Each child (member) has only one parent (owner)(owner)

Page 12: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 12

Example Hierarchy: Banking DatabaseExample Hierarchy: Banking Database

Customer# | SS# | Address| ...

Checking Acct. # | Current Balance | Statement Date

Check# | Date | Payee | Amount

Deposit# | Date | Amount

Savings Acct. # | Current Balance | Statement Date

Page 13: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 13

Simple NetworkSimple Network

Children may have more than one parentChildren may have more than one parent Example: Joint checking accountExample: Joint checking account

John Dough Jayne Dough

Checking Acct. # 999

Page 14: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 14

Complex NetworkComplex Network

Supports M:N relationshipsSupports M:N relationships

Students

Courses Securities

Portfolios

Page 15: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 15

Relational ModelRelational Model

Data organized into tables (relations)Data organized into tables (relations) Tables have columns (attributes)Tables have columns (attributes) Data stored in rows (tuples)Data stored in rows (tuples) Each row has a unique Each row has a unique primaryprimary keykey Relationships included in the Relationships included in the datadata

Page 16: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 16

Relational Tables and DataRelational Tables and Data

EMPLOYEE(EMPLOYEE(SS#, SS#, EmployeeName, EmployeeAddress, EmployeeName, EmployeeAddress, Department_IDDepartment_ID))

DEPARTMENT(DEPARTMENT(DEPARTMENT_IDDEPARTMENT_ID, DepartmentName, Manager), DepartmentName, Manager)

EMPLOYEEEMPLOYEE

SS#SS# EmployeeNameEmployeeName Employee AddressEmployee Address Department_IDDepartment_ID

12231223 John DoughJohn Dough Wall StreetWall Street AcctAcct

32143214 Jayne DoughJayne Dough Wall StreetWall Street FinFin

76537653 Jill OutleyJill Outley WellbornWellborn AcctAcct

DEPARTMENTDEPARTMENT

DEPARTMENT_IDDEPARTMENT_ID DepartmentNameDepartmentName ManagerManager

AcctAcct AccountingAccounting Beane KounterBeane Kounter

FinFin Finance Finance Cash McCallCash McCall

Page 17: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 17

MetadataMetadata

““Data about the data.”Data about the data.” Data dictionary - Data Definition LanguageData dictionary - Data Definition Language

– For each table or recordFor each table or record» Table or record name Table or record name

» Number of columns or FieldsNumber of columns or Fields

» Primary keyPrimary key

– For each data itemFor each data item» Date item nameDate item name

» Data type (Numeric, date, text...)Data type (Numeric, date, text...)

» SizeSize

Page 18: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 18

MetadataMetadata

Use DDLUse DDL Description Description

of database of database structurestructure

System tables System tables (e.g., tables (e.g., tables and columns)and columns)

Page 19: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 19

IndexesIndexes

Usually “inverted lists” for accessing data.Usually “inverted lists” for accessing data.

DepartmentDepartment EmployeesEmployees

AcctAcct 1223, 76531223, 7653

FinFin 32143214

Page 20: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 20

Indexes and other data structuresIndexes and other data structures

Improve performance for sorting and Improve performance for sorting and searchingsearching

But: overhead of updatingBut: overhead of updating Who has Info Systems as major?Who has Info Systems as major?

Page 21: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 21

Application MetadataApplication Metadata

Structure & format of application Structure & format of application componentscomponents– FormsForms– ReportsReports– QueriesQueries– Etc.Etc.

Page 22: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 22

FormsForms

Data entryData entry Hiding IDsHiding IDs

Page 23: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 23

QueriesQueries

By example (QBE)By example (QBE) By formBy form By DML (Data Manipulation Language)By DML (Data Manipulation Language)

Page 24: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 24

ReportsReports

Data displayData display

Page 25: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 25

MenusMenus

Organize application componentsOrganize application components

Page 26: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 26

Application programsApplication programs

DMLsDMLs Standard Standard

languages + languages + DBMS DBMS interfaceinterface

Eg: trapping Eg: trapping events in events in Visual Basic Visual Basic + Access+ Access

Page 27: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 27

DBDBSystemSystemArchitectureArchitecture

Page 28: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 28

The Database SchemaThe Database Schema

TablesTables RelationshipsRelationships DomainsDomains

– constraints on values that a column may have.constraints on values that a column may have.

– e.g. date, integer number, text of length N...e.g. date, integer number, text of length N...

– ID’s (primary keys) must be uniqueID’s (primary keys) must be unique

Business rulesBusiness rules– Rules or policies that must be enforced in the database.Rules or policies that must be enforced in the database.

» Each employee is always assigned to one department.Each employee is always assigned to one department.

» Each department is always assigned one or more employees. Each department is always assigned one or more employees.

Page 29: Stephen C. Hayne 1 Database System Components The Database and the DBMS

Stephen C. Hayne 29

SummarySummary

Database Systems includeDatabase Systems include– the database consisting ofthe database consisting of

» Data, Metadata, Indexes, Application metadataData, Metadata, Indexes, Application metadata

– the database management system (DBMS)the database management system (DBMS)» Design Tools & Run Time ToolsDesign Tools & Run Time Tools