Top Banner
1 Databases 2013/2014 Introduction
25

1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

Apr 01, 2015

Download

Documents

Dwight Heward
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

1

Databases 2013/2014

Introduction

Page 2: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

2

The menu for today

• Organisational aspects

• Introduction to database technology

• The relational model

Page 3: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

About using laptops in classes

3

Page 4: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

Organisation

• Hoorcollege• Donderdag a.s. in Went-blauw, eenmalig

• Werkcolleges (beginnen volgende week dinsdag)

• Huiswerkopgaven (3x)

• Practica• Opgave 1: casusbeschrijving, modelleren,

schema-ontwerp• Opgave 2: vulling van de database, SQL

queries• Voor elke opgave twee practicumsessies op

tijden werkcollege4

Page 5: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

5

Introduction to database tech.

• What are databases?• Relational data model (short version)

• Why should we look at databases?• Short history of databases• Some aspects of database technology

• Query languages• Database applications: 4GL, constraints, reports• ER-modeling• Normalisation• Transaction processing

Page 6: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

6

What are databases? (1)

• Example: library system• Books, readers, loans, reservations• Loaning books, returning books, searching,

making reservations, subscribing readers

Bno Author Title

327 Gates The road ahead535 Baars Fun-fishing113 Kasparov Chess for dummies

Rno Name Address

212 Rutte Torentje 1, Den Haag431 Kramnik Plein 2, Wladiwostok7 Bond Downing Str. 7, London

Bno Rno Loan date Return date

113 431 14.10.2008 17.10.2008327 212 21.10.2008 -535 212 28.10.2008 -

Book Reader

Loan

Page 7: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

7

What are databases? (2)

• Manipulation of data using

a query language• For example SQL

• Integrated in a 4GL

• Often client/server architecture• Application logic in the client

SELECT TitleFROM BookWHERE Author = ‘Kasparov’

Database server (DBMS)

Client

Database

Page 8: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

8

What are databases? (3)

• Characteristics of a database environment

• Stable structure of data

• Large volumes (external memory, persistency)

• Good performance

• More than one user at a time

• Reliability and integrity of data

• Conceptual approach

Page 9: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

9

Why look at databases?

• Databases are omnipresent

• Database technology is directly applicable

• Database technology is the backbone of most information systems

• Studying database technology provides insight in general principles of computer science• Layered software architecture

• Application of predicate logic

• Mathematical modeling

Page 10: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

10

(Pre)History of databases (1)

• Magnetic tapes were available in 1945• searching in external memory

• IBM introduced the RAMAC system in 1957• hard disk

• In 1961, Integrated Data

Store was the first general

DataBase Management

Systeem (DBMS)

Page 11: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

11

(Pre)History of databases (2)

• The Information Management System by IBM followed in the mid-sixties• Hierarchical data model

• In the same era the Network Data model became popular (CODASYL standard)

• During the seventies, the commercial use of databases was rapidly growing

• Codd proposed the relational data model in 1970• The basis of almost all modern DBMSes

Page 12: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

12

History of databases (3)

• In 1976, Chen introduced the Entity-

Relationship (ER) model

• Conceptual modeling for databases

• Simplified the design of databases

• Query languages such as SEQUEL (SQL),

QBE and QUEL were designed

Page 13: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

13

History of databases (4)

• During the early eighties, the relational data

model received widespread commercial

attention

• In 1983, more than 100 RDBMSes existed

• DB2, ORACLE, SYBASE, INFORMIX, INGRES

• DBASE, PARADOX, MS-ACCESS

• SQL became a “standard” in 1986

• SQL92/SQL2, SQL3, SQL2003: ANSI standards

Page 14: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

14

History of databases (5)

• The first 4GL languages appeared during the eighties

• Object-oriented databases were introduced at the end of that decade

• Focus shifted to extending features and better performance• Multimedia databases, web databases, parallel

processing

• Core database technology is now quite “stable”• Databases + …

Page 15: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

15

Query languages

• From “how” to “what”• SQL is declarative

SELECT NameFROM Book, Loan, ReaderWHERE Book.Title = ‘Fun-fishing’ AND Book.Bno = Loan.Bno AND Loan.Rno = Reader.Rno

Book.Title := ‘Fun-fishing’;FIND FIRST Book USING Title;WHILE DB-Status = 0 DOBEGIN FIND FIRST Loan WITHIN Book_Loan; WHILE DB-Status = 0 DO BEGIN FIND OWNER WITHIN Reader_Loan; GET Reader; PRINT(Reader.Name); FIND NEXT Loan WITHIN Book_Loan; END; FIND NEXT Book USING Title;END

Page 16: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

16

Database applications (1)

PROCEDURE Loan;begin $today := call_system(‘current_date’); read($x); # read Rno

if call(Rnocheck($x)) = 0 then begin message(“ticket invalid”); exit end;

read($y); # read Bno while ($y <> EndOfLoan) do begin call(Register_loan($today, $x, $y)); read($y); endend {Loan}

PROCEDURE Rnocheck($x);begin SELECT COUNT (*) FROM Reader WHERE Rno = $x;end {Rnocheck}

PROCEDURE Register_loan ($today, $x, $y);begin INSERT INTO Loan VALUES ($y, $x, $today, NULL);end {Register_loan}

Page 17: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

17

Database applications (2)

CONSTRAINT constr1 (SELECT COUNT (*) FROM Loan WHERE Return_date IS NULL GROUP BY Rno) <= 6ON VIOLATION …

CONSTRAINT constr2 (SELECT COUNT (*) FROM Loan WHERE Return_date IS NULL GROUP BY Bno) <= 1ON VIOLATION …

CONSTRAINT constr3 (SELECT Bno FROM Loan) IS CONTAINED IN (SELECT Bno FROM Book)ON VIOLATION …

Page 18: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

18

Database applications (3)

• Report writing

@name@address

Dear mr/mrs @name,

On @loan_date you have borrowed the following book from our library:@title by @author.

We kindly request you to return this book as soon as possible.

SELECT Name, Address, …FROM Loan, Reader, BookWHERE Loan.Rno = Reader.Rno AND Loan_date < ‘01.12.2010’ AND Return_date IS NULL

Page 19: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

19

Database applications (4)

Database server (DBMS)

User interfaceApplication programs

Database

SQL Data

DataFile access

Sophisticated user(DataBase Administrator,

developer)

SQL QueriesUpdates

MenusScreensReports

Naive user

Page 20: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

20

ER modeling

Book Reader

Loan

(0, n) (0, m)

Loan date Return date

NameAddress

RnoBno

TitleAuthor

Book(Bno, Author, Title)

Reader(Rno, Name, Address)

Loan(Bno, Rno, Loan_date, Return_date)

Page 21: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

21

Normalisation (1)

• Why don’t we put everything in one table?• Manageability• Prevent redundancy and inconsistency• Adequate representation (without NULLs)

• Normalisation• “Vertical” splitting of tables• Several distinct normal forms and algorithms

Rno Name Address Bno Author Title

212 Rutte Torentje 1, Den Haag 327 Gates The road ahead212 Rutte Torentje 2, Den Haag 535 Baars Fun-fishing431 Kramnik Plein 2, Wladiwostok 113 Kasparov Chess for dummies7 Bond Downing Str. 7, London NULL NULL NULL

Page 22: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

22

Normalisation (2)

Bno Author Title

327 Gates The road ahead535 Baars Fun-fishing113 Kasparov Chess for dummies

Rno Name Address

212 Rutte Torentje 1, Den Haag431 Kramnik Plein 2, Wladiwostok7 Bond Downing Str. 7, London

Bno Rno Loan_date Return_date

113 431 14.10.2006 17.11.2006327 212 21.10.2006 -535 212 28.10.2006 -

Rno Name Address Bno Author Title

212 Rutte Torentje 1, Den Haag 327 Gates The road ahead212 Rutte Torentje 1, Den Haag 535 Baars Fun-fishing431 Kramnik Plein 2, Wladiwostok 113 Kasparov Chess for dummies7 Bond Downing Str. 7, London NULL NULL NULL

Page 23: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

23

Transaction processing (1)

• Transactions are important in case of crashes and simultaneous use of the database by multiple users• Transactions transform multiple database

operations into one single atomic operation (as seen from the outside)

Read balance accno. 1234567Read balance accno. 7654321Withdraw € 50,- from 1234567Deposit € 50,- on 7654321Write balance accno. 1234567Write balance accno. 7654321

CRASH!

Page 24: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

24

Transaction processing (2)

1. Read balance accno. 12345672. Read balance accno. 1234567

1. Withdraw € 500,- from 12345672. Withdraw € 500,- from 1234567

1. Write balance accno. 12345672. Write balance accno. 1234567

• Concurrency problem• Solved by locking based techniques

Page 25: 1 Databases 2013/2014 Introduction. 2 The menu for today Organisational aspects Introduction to database technology The relational model.

25

Why relational databases?

• Software Engineering• High level data specification and manipulation

• Philosophy with regard to system development• Start with rigorous design of tables

• Stable; detailed inventarisation is possible

• Development of operations is secondary• Difficult to analyse, rapid prototyping, continuous

adaptation

• Successful application of computer science• Set theory, predicate logic, optimisation, design

theory