12
Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related information Repository / storage of information Examples: Grocery list Phone book

Databases and DBMS · 1 Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Databases and DBMS · 1 Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related

1

Databases and DBMS

Eric Lew (MSc, BSc)

SeconSys Inc.Nov 2003

What is a Database ?

Data (singular: datum)Factual Information

DatabaseOrganized body of related informationRepository / storage of information

Examples:Grocery listPhone book

Page 2: Databases and DBMS · 1 Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related

2

Data Organization

Grocery list:Apples (2)BreadYoghurtPaper plates (20)Lettuce (2)Chicken drumsticksMushroomsCheeseSpaghettiPork ribsCilantro

Tomato SaucePlastic forks (20)OrangesIce creamPlastic knives (20)ParsleySour creamTomatoesBaconPaper napkinsSpinach

Data Organization (II)Grocery list:Fresh Produce:

Oranges (1 lb)Apples (2 lbs)Lettuce (2)SpinachMushrooms (white)ParsleyCilantroTomatoes (plum)

Meats:Pork ribs (3 lbs)Bacon (1 lb)Chicken drumsticks (20)

Dairy:Yoghurt (low fat)Sour creamIce creamCheese (mozarella)

Other:Bread (white sliced)SpaghettiTomato SaucePlastic forks (20)Plastic knives (20)Paper napkins (20)Paper plates (20)

Page 3: Databases and DBMS · 1 Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related

3

Data ModelsConceptual Model

What is the data aboutHow will the data be usedEntity-Relationship (ER) diagram

Logical ModelImplementation dependent

Network, Hierchical - obsoleteRelational - the current standardObject-oriented - the future?

Physical ModelHow is the data physically stored and retrievedHardware and software dependent

Page 4: Databases and DBMS · 1 Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related

4

Relational Data Model

Data organized as a collection of tablesEach table represents an entity type

Consists of rows and columnsEach row contains the data values of one entityEach column represents an attribute (property) of the entity

Technical terms:Table = relationRow = tuple, recordColumn = attribute, fieldDomain = cell value

Relational Data Model - Example

Page 5: Databases and DBMS · 1 Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related

5

Relational Concepts

Attribute valuesData types: character, number, logical, dateRange constraint; e.g. 1.0 to 9.9Enumeration contraint; e.g. ‘RED’, ‘BLUE’, ‘GREEN’Null value means unknown data

No two rows can be identicalPrimary key: attribute(s) which uniquely identify a row

Relational Database Design

A cell should only have one valueMinimize data redundancy (reduce human error)

Replace one big table by several small tablesTechnical term: normalization

Use ‘small’ attributes for primary keysMore efficient use of spaceFaster retrieval of data

Page 6: Databases and DBMS · 1 Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related

6

Relational Database – Bad Design

James Cookbook1, book2Software 10111 Bright CrescentChet Davis

Jennifer YatesBook6History 2027 Hilly LaneJill Aries

Bill Gomezbook3Psychology 20192 Sunlight Rd.Mia Rowe

James Cookbook1, book2Software 10189 Lilac Dr.John Bell

Jennifer Yatesbook6History 201117 Rose DriveAlan Gold

Jenny Yatesbook6History 20292 Sunlight Rd.Mia Rowe

James Cookbook4, book5Database 10111 Bright Cres.Chet Davis

Bill Gomezbook3Psychology 201675 West LaneLaura Holm

ProfessorBooksCourseAddressStudent

Relational Database - Good DesignStudent

117 Rose DriveAlan Gold16

7 Hilly LaneJill Aries15

92 Sunlight Rd.Mia Rowe14

11 Bright Cres.Chet Davis13

675 West LaneLaura Holm12

89 Lilac Dr.John Bell11

AddressNameID

Professor

Jennifer Yates3

Bill Gomez2

James Cook1

Prof_NameID

Course

3History 20135

3History 20234

Database 101

Psychology 201

Software 101

Name

133

232

131

Prof_IDID

StudentCourse

3214

3113

3415

3516

3414

33

32

31

Cour_ID

13

12

11

Stu_ID

Page 7: Databases and DBMS · 1 Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related

7

Relational Concept: Join

Relationship between tables identified by primary keys and foreign keys

Primary key (PK) in Professor table is ‘ID’Foreign key (FK) in Course table is ‘Prof_ID’Primary and foreign key must be same data type

Joining tables: compare FK value and PK valueCourse.Prof_ID = Professor.ID

Relationship types:One-to-oneOne-to-manyMany-to-many

Relational Database Management SystemSeparate application from data

Several applications can use same dataTables can be added to database incrementally

Multi-user concurrent access to dataMaintenance of data integrity

Enforce validation of dataBack-up and recovery

Transaction managementAll or nothing (eg. Bank transfer)

SQL: Structured Query LanguageStandard language for all relational DBMS

Page 8: Databases and DBMS · 1 Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related

8

Structured Query LanguageINSERT command

One row at a timeINSERT INTO Student (ID, Name) VALUES (20, ‘Adam Wright’)

DELETE commandDELETE FROM StudentCourse WHERE Stu_ID = 20

UPDATE commandUPDATE Course SET Prof_ID = 3 WHERE Name LIKE ‘History%’

SELECT commandSELECT * FROM Student WHERE ID > 10SELECT Course.Name, Prof_Name FROM Course, Professor

WHERE Course.Prof_ID = Professor.ID

Stored ProceduresBlocks of SQL commands

Implement business rulesReusable – used by multiple applications

Stored in the DBMS (hence the name)Compiled at time of creation

Faster runtime executionNo syntax errors at run-time

Language varies from one DBMS to anotherOracle: PL/SQLMicrosoft: Trans-SQL

Page 9: Databases and DBMS · 1 Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related

9

Stored Procedure - ExampleCREATE PROCEDURE TransferMoney

@acctNum1 CHAR(15),@acctNum2 CHAR(15),@amount FLOAT

ASDECLARE @balance FLOATBEGIN TRANSACTIONSELECT @balance = Balance FROM Savings WHERE Account = acctNum1IF (@balance < @amount) THEN

ROLLBACK TRANSACTIONRETURN (-1)

END IFUPDATE Savings SET Balance = Balance - @amount WHERE Account = acctNum1UPDATE Savings SET Balance = Balance + @amount WHERE Account = acctNum2COMMIT TRANSACTIONRETURN (0)

Georelational Data Model

Hybrid data model (logical model)Topological data mode (represents spatial data)Relational DBMS (represents attribute data)

Geographic data represented by LayersRoads, streams, land cover…Each layer is stored in a separate table

Spatial objects classified by graphical formPoints, Lines and Polygons are stored in separate tables

Page 10: Databases and DBMS · 1 Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related

10

Georelational Example

Geodatabase

Storage of geo information within DBMSVersioning

Multi-user editingMultiple representations of dataLong transactions

BehavioursValidation rules: domains, sub typesDefault values

Page 11: Databases and DBMS · 1 Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related

11

Object-Oriented Data ModelEntities represented as objects

Object classes (types)Objects have properties (attribues)Objects have methods (operations)

Classes and InheritanceClass hierarchy – super and sub classesCreation of new classes: Point, Line, Polygon

Operations and EncapsulationData and operations bundled togetherPolymorphism: classes Rectangle and Circle can have same operation CalculateArea

Object-Oriented DBMS

Not widely accepted currentlyLack of standard query languagePortability issuesNot as efficient as Relational DBMSBig name RDBMS have too much marketing clout

Page 12: Databases and DBMS · 1 Databases and DBMS Eric Lew (MSc, BSc) SeconSys Inc. Nov 2003 What is a Database ? Data (singular: datum) Factual Information Database Organized body of related

12

DBMS in an Enterprise

GeoDatabase Sales Database

Application Server

ArcObjects

Sales Report

MapInfoInventory

Web Server