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
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
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
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
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
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
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
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)
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
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
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
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 + …
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
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}
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 …
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
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
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)
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
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
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!
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
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
Top Related