120 likes | 212 Views
Essential Databases. The simple truth!. 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). The Data Model. model
E N D
Essential Databases The simple truth!
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)
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
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
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!
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?
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
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
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.
… 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)
(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 primarykey is that chosen by a DB designer for this purpose • a foreignkey is one that coexists in another relation
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