database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database...

38
Database Review

Transcript of database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database...

Page 1: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Database Review

Page 2: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Outline

DefinitionsHistoryBasic concepts of DBMSData ModelsRelational databaseNormalization

Page 3: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Definitions

Database: an organized collection of dataRelational database: a database based on

the relational modelDatabase management system: a

computer program (or a suite of programs)designed to manage a database, and runoperations on the data requested bynumerous consumers

Source: www.en.wikipedia.org

Page 4: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

History

1960's: Two main data models were developed:network model (CODASYL - COnference onDAta SYstems Languages) and hierarchical(IMS - Information Management System).

1970-72: Edgar Frank Codd proposed relationalmodel for databases - disconnects the schema(logical organization) of a database from thephysical storage methods.

Page 5: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

History

1970's: Two main prototypes for relational systems weredeveloped during 1974-77. Ingres: Developed at UCB

led to Ingres Corp., Sybase, MS SQL Server, Britton-Lee,Wang's PACE.

used QUEL as query language.System R: Developed at IBM San Jose

led to IBM's SQL/DS & DB2, Oracle, HP's Allbase, Tandem'sNon-Stop SQL.

used SEQUEL (Sequential English QUEry Language) asquery language.

The term Relational Database Management System(RDBMS) is coined during this period.

Page 6: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

History

1976: P. Chen proposed the Entity-Relationship(ER) model for database design.

Early 1980's: Commercialization of relationalsystems begins

Mid-1980's: SQL (Structured Query Language)becomes standardDB2 becomes IBM's flagship product.Development of the IBM PC gives rise to many DB

companies and products such as RIM, RBASE 5000,PARADOX, OS/2 Database Manager, Dbase III, IV(later Foxbase, even later Visual FoxPro), Watcom SQL.

Page 7: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

History

Early 1990's: companies offering increasingly complexproducts at higher prices. development centers on client tools for application such as

PowerBuilder (Sybase), Oracle Developer, VB (Microsoft),etc.

Client-server model for computing becomes the norm forfuture business decisions.

Development of personal productivity tools such asExcel/Access (MS) and ODBC.

This also marks the beginning of Object DatabaseManagement Systems (ODBMS) prototypes.

Mid-1990's: Internet/WWW appears.Web/DB grows exponentially.

Page 8: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

History

Late-1990's: Boom in Web/Internet/DBconnectors.Active Server Pages, Front Page, Java Servlets, JDBC,

Enterprise Java Beans, ColdFusion, Dream Weaver,Oracle Developer 2000, etc.

Open source solution come onlinewidespread use of gcc, cgi, Apache, MySQL, etc.Online Transaction processing (OLTP) and online

analytic processing (OLAP) comes of age with manymerchants using point-of-sale (POS) technology on adaily basis

Page 9: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

History

Early 21st century: Decline of the Internetindustry as a wholesolid growth of DB applications continues.More interactive applications appear with use of PDAs,

POS transactions, consolidation of vendors, etc. Threemain (western) companies predominate in the large DBmarket: IBM (buys Informix), Microsoft, and Oracle.

Future trendsLarge data sizeMobile computing

Page 10: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Problems with Conventional FileSystemsData redundancy and inconsistencyDifficulty in accessing dataData isolationMultiple usersSecurity problems Integrity problems

Page 11: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

DBMS

Characteristics:Self-containedInsulation between programs and dataData abstractionSupport of multiple views of the data

Page 12: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

DBMS

Intended uses: Controlling redundancy Sharing of data - concurrency control Restricting unauthorized access Providing multiple interfaces Representing complex relationships among data Enforcing integrity constraints Providing backup and recovery

Page 13: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

DBMS Advantages

Potential for enforcing standardsFlexibilityReduced application development timeAvailability of up-to-date informationEconomies of scale

Page 14: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Data Abstraction

Data abstraction is an abstract view of thedatabase system

Three levels of data abstractionPhysical level - how data are stored

physicallyConceptual level - what data are stored,

relationship among dataView level - which parts of data a specific

user can view

Page 15: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Data Models

Object-based logical data modelER modelObject-oriented model

Record-based logical data modelRelational modelNetwork modelHierarchical model

Physical data model

Page 16: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

E-R Model

Consists of entities (objects) andrelationships among those entities

Each entity has a set of attributesdescribing it

Can be described using E-R diagram

Page 17: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

E-R Diagram

Graphical expression of a logical structure ofa databaserectangles: represent entity sets.ellipses: represent attributes.diamonds: represent relationships among entity

sets.lines: link attributes to entity sets and entity sets

to relationships.

http://wofford.org/ecs/DataAndVisualization/ermodel/material.htm

Page 18: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Example of E-R Diagram

http://www.conceptdraw.com/products/img/ScreenShots/cd5/software/Chen_ERD.gif

Page 19: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Relational Model

Represents data and relationships withtables

Attributes are represented as columns ineach table

Each column must have a unique name

Page 20: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Example of Relational Database

Sirima Li3IT1

Santi Li4Math2

Anne Taylor1IT1Faculty_NameFaculty_IDDept_NameDept_ID

$2300Santi Li4$2000Sirima Li3$2500Anne Taylor1Faculty_SalaryFaculty_NameFaculty_ID

Page 21: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Physical Data Model

Describes data at the lowest levelDepends on physical DBMS

Page 22: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Technical Terms Comparison

FieldColumnAttributeRecordRowTupleEntityTableRelation

A.K.ACommonName

FormalName

Page 23: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Relational Operations

Query: selectUpdate: insert, update, deleteTables manipulation: create table, drop

table, alter table Index manipulation: Create index, drop

indexView manipulation: Create view, drop view

Page 24: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

SELECT

Select a subset of tuples in a relationSELECT field(s) FROM table_nameWHERE condition

ORDER BY field(s)ExampleSELECT customer_name,credit_limit,addressFROM customer WHERE slsrep_number = 6ORDER BY credit_limit, current_balance

Page 25: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

INSERT

Add a single tuple to a relationINSERT INTO table_name VALUESvalues to be inserted in columns

Example:INSERT INTO slsrep

VALUES (10, ‘Mark’, ‘1400 Joyce St.’,0.00, 0.05)

Page 26: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

DELETE

Remove tuples from a relationDELETE table_name WHERE condition

ExampleDELETE customer WHERE name=‘Mark’

Page 27: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

UPDATE

Modify attribute values of one or moreselected tuples

UPDATE table_name SET column = valueWHERE condition

ExampleUPDATE customer SET name = ‘Ann’WHERE customer_number = 100

Page 28: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Normalization

The process of converting a complex datastructure intosimplest structuremost stable structure

By removing redundant attributes, keys,and relationships from a conceptualdata model

Page 29: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

1NF

First normal form (1NF) entity is achievedby removing repeating or multivaluedattributes to another, child entity.

Page 30: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Example

ORA

DTCASI

TOS

Cust

$6

$5$12

$10

$10$5

Prd_Price

Saw

PlierHammer

Hammer

HammerSaw

Prd_Dscr

202031006005

515

31

031006004151021006003

2010

12

021006001

Prd_QTY

Prd_ID

Order_Date

Order_ID

Page 31: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Example

First Normal Form

ORNDTCDTCASITOSTOS

Cust

10$5Saw2021006001

15$12Hammer1031006004$6

$5$10

$10

Prd_Price

Saw

PlierHammer

Hammer

Prd_Dscr

202031006005

53031006004151021006003

201021006001

Prd_QTY

Prd_ID

Order_Date

Order_ID

Page 32: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

2NF

First normal form entities can be reducedto second normal form (2NF) by removingattributes that are not dependent on thewhole primary key.

Page 33: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Example

First Normal Form

ORNDTCDTCASITOSTOS

Cust

10$5Saw2021006001

15$12Hammer1031006004$6

$5$10

$10

Prd_Price

Saw

PlierHammer

Hammer

Prd_Dscr

202031006005

53031006004151021006003

201021006001

Prd_QTY

Prd_ID

Order_Date

Order_ID

Page 34: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Example

Second Normal Form

10$5Saw2021006001

15$12Hammer1031006004$6

$5$10

$10

Prd_Price

Saw

PlierHammer

Hammer

Prd_Dscr

202031006005

53031006004151021006003

201021006001

Prd_QTY

Prd_ID

Order_Date

Order_ID

ORA005DTC004ASI003TOS001

CustOrder_ID

Page 35: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

3NF

Second normal form entities can bereduced to third normal form (3NF) byremoving attributes that depend on other,nonkey attributes (other than alternativekeys).

Page 36: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Example

Second Normal Form

10$5Saw2021006001

15$12Hammer1031006004$6

$5$10

$10

Prd_Price

Saw

PlierHammer

Hammer

Prd_Dscr

202031006005

53031006004151021006003

201021006001

Prd_QTY

Prd_ID

Order_Date

Order_ID

Page 37: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Example

Third Normal Form

102021006001

151031006004202031006005

53031006004151021006003

201021006001

Prd_QTY

Prd_IDOrder_DateOrder_ID

$5Plier3$5Saw2

Hammer

Prd_Dscr

$101

Prd_Price

Prd_ID

Page 38: database - KMUTTwebstaff.kmutt.ac.th/~iauaroen/618341/database.pdf · The term Relational Database Management System ... This also marks the beginning of Object Database Management

Denormalization

the process of attempting to optimize theperformance of a database by addingredundant data

sometimes necessary because currentDBMSs implement the relational modelpoorly

Source: www.en.wikipedia.org