essential databases the simple truth!. what’s a database? a system which helps with –storage...

12
Essential Databases The simple truth!

Upload: meghan-brown

Post on 17-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Essential Databases The simple truth!. What’s a database? A system which helps with –storage –retrieval in an efficient manner –assume large volumes of

Essential Databases

The simple truth!

Page 2: Essential Databases The simple truth!. What’s a database? A system which helps with –storage –retrieval in an efficient manner –assume large volumes of

What’s a database?

• A system which helps with– storage– retrieval

• in an efficient manner– assume large volumes of data

• paradigm - relational– (will also cover OODB)

Page 3: Essential Databases The simple truth!. What’s a database? A system which helps with –storage –retrieval in an efficient manner –assume large volumes of

The Data Model

• model– an artificially constructed device which

approximates to a part of tha real world

• good model– properties of the model correspond to

properties of the real world

• for all models– not always the case

Page 4: Essential Databases The simple truth!. What’s a database? A system which helps with –storage –retrieval in an efficient manner –assume large volumes of

In a database…

• the model is used to give– understanding to users/programmers

• tools to populate the database

– tools to check queries make sense• soundness

– optimisation for queries• increasingly less important for many databases

Page 5: Essential Databases The simple truth!. What’s a database? A system which helps with –storage –retrieval in an efficient manner –assume large volumes of

Creating a database

• phase 1– design the schema

• nothing else can happen until this is fixed

• it can never be subsequently changed!!

• phase 2– define queries, views etc.

• phase 3– hand over to users to populate and use database

• leave without forwarding address!

Page 6: Essential Databases The simple truth!. What’s a database? A system which helps with –storage –retrieval in an efficient manner –assume large volumes of

The entity/relationship approach

• decide which real-world entities to model– eg people, cars, buildings etc.

• decide what attributes each entity has– eg age, name, address etc.

• decide what relationships exist among entities– eg owns, lives_at, employee_of etc

• sounds easy?

Page 7: Essential Databases The simple truth!. What’s a database? A system which helps with –storage –retrieval in an efficient manner –assume large volumes of

Entity-relationship diagrams

• just pictures capturing the above in some kind of coded form– lots of different notations exist…

• usual communication medium amongst designers, between designers and programmers etc.

• some systems allow them as basic input– play with MS Access

Page 8: Essential Databases The simple truth!. What’s a database? A system which helps with –storage –retrieval in an efficient manner –assume large volumes of

The Relational Model

• everything is coded as a relation– entities and relationships

• think of them as tables…– with care: no duplicates, no update

• the model doesn’t quite match the real world– it’s easy and dangerous to forget that

Page 9: Essential Databases The simple truth!. What’s a database? A system which helps with –storage –retrieval in an efficient manner –assume large volumes of

Modeling entities ...

• straightforward for regular data

• think of:– relation as a table– entities as rows

• remember no repeats!

– attributes as columns• with basic scalar types eg int, string, date etc.

Page 10: Essential Databases The simple truth!. What’s a database? A system which helps with –storage –retrieval in an efficient manner –assume large volumes of

… and relationships

• how to capture an arbitrary relationship in a relation?

• relationships are between entities (rows) in other tables

• first n columns can uniquely identify entity in one relation,

• next m columns can uniquely identify entity in another relation.– (notice underlying strong theories)

Page 11: Essential Databases The simple truth!. What’s a database? A system which helps with –storage –retrieval in an efficient manner –assume large volumes of

(Relational) Keys

• a key is a subset of a relation’s attributes, the values of which uniquely identify every attribute– they can change according to the values present

• a primary key is that chosen by a DB designer for this purpose

• a foreign key is one that coexists in another relation

Page 12: Essential Databases The simple truth!. What’s a database? A system which helps with –storage –retrieval in an efficient manner –assume large volumes of

Modeling relationships again…

• we now know we can model any relationship– a new relation containing foreign keys for the

two original relations

• each row in such a relation gives a two-way link– between rows in the two original relations

• can model any kind of relationship– one-one, one-many, many-one, many-many