lis512 lecture 1 the entity-relationship model thomas krichel 2010-09-22

38
LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

Upload: hubert-mckenzie

Post on 25-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

LIS512 lecture 1

the entity-relationship model

Thomas Krichel2010-09-22

Page 2: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

today

• entities• entity sets• relations• identifiers• building a sophisticated description…

Page 3: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

entity• An entity is something that is – we are interested in to describe– we can distinctly identify

• What you look at as an entity depends on what you want to be doing.

• For example, if you look at persons, you may restrict this to living people. Or you may included only people we think have actually lived.

• FRBR (next week) talks about entities in libraries.

Page 4: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

attributes to an entity

• Each entity is described by a bunch of attributes.

• Each attributes has a name.• Each attribute takes a value.• We can say that we have an attribute/value

pair.• Example “birthday: 1965-06-05”.

Page 5: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

another attribute example

• Let us say we have an entity called person.• Each person has– birthday– sex – height– weight

• We can use this data, together with the present time, to determine if the person is overweight.

Page 6: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

another example

• a person – name: Thomas– email: [email protected]– age: 48

• some other person– name: Jose– email: [email protected]– age: 37

Page 7: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

tables

• We often write information about entities in a table.

• Each row in the table describes an entity. • The different columns contain values of

attributes of the entity.• Remember, this is just a way to write things.

Page 8: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

example

• name | email address | age• Thomas | [email protected] | 48• Jose | [email protected] | 37• Feng | [email protected] | 42

Page 9: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

records in a table

• In fact, in the table we have a sequence of records.

• Each record describes an entity.• The fact that there is a sequence is imposed

by the fact that we list the records about each entity in a table.

Page 10: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

set

• “set” is the most ambiguous word in the English language.

• In the mathematical set, it a set is a bunch of elements (or members) without any order between them.

• Most of the time, entities out there come in sets.

Page 11: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

entity sets

• A group of entities is called an entity set. Each member in the set takes the same attributes. But the value that the attributes take may be different for different members in the set.

• Usually, entities in an entity set are commonly understood, such as users, books and libraries.

• But if you think about your problem a bit more, you realize that the issue is not that simple.

Page 12: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

entity and entity set example

• A book is an entity.• It has an attribute called “author”. The value is

“Karl Marx”. • It has an attribute called “title”. The value is

“Das Kapital”.• A book is something that has a title, an author

etc. • All books form a set.

Page 13: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

relationships

• The entity relationship model comes to live when we look relationship.

• We have a relationship between entities sets when elements of one set may be related to elements in another entity set.

• For example, consider books and people.

Page 14: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

symmetric relationships

• Sometimes relationships are symmetric. When one entity is related to another, the other has exactly the same relationship with the one.

• “being married to” is a symmetric relationship.• “being husband of” is mostly not.

Page 15: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

relationship types

• Usually, relationships are grouped by three types.

• There are one-to-one relationships.• There are one-to-many relationships.• There are many-to-many relationships.

Page 16: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

one-to-one relationship

• Look at two entity set.• In a one-to-one relationship, each entity in

one set is connected to one in the other set.• In a library setting, I did not find an example.• Look at cars on the road. – each car has one driver– there is one driver in each car

• one-to-one relationships are uncommon.

Page 17: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

many-to-one relationship

• Consider two entity sets, people and books.• Each person has a favorite book. • But a book can be the favorite book of more

than one person. • “is favorite-book of” is a many-to-one

relationship between books and people. • “has favorite book” is a one-to-many

relationship between people and books.

Page 18: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

many-to-many relationships

• Look at two entity sets, libraries and persons. • The relationship “patronizes” is a many-to-

many relationship between persons and libraries.

• The relationship “is patronized by” is a many-to-many relationship between libraries and persons.

Page 19: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

relationship in the library world

• Imagine entity sets “libraries”, “books”, “users”.

• We can draw three relationships.– Users read books. – Users patronize libraries.– Libraries store books.

Page 20: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

examples

• Brentwood Public Library has a copy of Moby Dick.

• Purchase Public Library has a copy of Moby Dick.

• Thomas reads Moby Dick.• Thomas patronizes Brentwood Public Library.

Page 21: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

tables

• Remember that in a database records are represented as lines in a table. The first line of the table lists the field names. Here is a sample table with two records

|name | birthday | | Thomas Krichel| 1965-06-05| | Karl Marx | 1818-05-13|

Page 22: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

identity

• Consider an extract from the same table |name | birthday | | Thomas Krichel | 1965-06-05| | Thomas Krichel | 1965-06-05|• Is the record a duplicate?• Without further information, we can not tell.• Certainly, no computer can tell.

Page 23: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

identity and key

• Identity can only be conferred by a human.• Often that is some sort of information worker.• A information processing system can not find

identity.• But there are there are tools that are used to

encode the identity in an information system.

Page 24: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

key

• To be able to find what records describe the same entities, databases use a construct called a key.

• An attribute is a key if the value taken by the attribute must be different for each entity.

• Unusually, there is only one key attribute. In that case the value taken by the key attribute is called the identifier of the entity.

Page 25: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

examples

• Here is a correct example|key|name | birthday ||2 | Thomas Krichel | 1965-06-05|| 1 | Thomas Krichel | 1965-06-05|

• Here is an incorrect example|key|name | birthday ||1 | Thomas Krichel | 1965-06-05||1 | Thomas Krichel | 1965-06-05|

Page 26: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

identity

• Identity is simple when it comes to person.• But when it comes to other entities we are

interested in the world of libraries.• Identifiers and the handling of them is one of

the most difficult issues of digital librarianship.• If I have two copies of the same book are they

the same book or are they different books?• FRBR gives us some answer next week…

Page 27: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

why bother with identity

• Once we have identified an entity in an entity set, we can create a relationship with an entity in another set, or in the same set.

• Once we have done this, we can– encode a much richer description– maintain it at relatively low cost.

• This can be illustrated with the introduction of a relational database.

Page 28: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

relations

• Not all database system are relational.• The most widely used ones are relational.• That means you can build relationships

between tables and enforce them. • I am coming to this from an old example.

Page 29: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

relational databases

• A relational database is a set of tables. There may be relations between the tables.

• Each table has a number of records. Each record has a number of fields. They give us values that attributes take for the entity described.

• Let us look at this bottom up.

Page 30: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

example: Movie databaseID | title | director | dateM1 | Gone with the wind | F. Ford Coppola | 1963M2 | Room with a view | Coppola, F Ford | 1985M3 | High Noon | Woody Allan | 1974M4 | Star Wars | Steve Spielberg | 1993M5 | Alien | Allen, Woody | 1987M6 | Blowing in the Wind | Spielberg, Steven | 1962

• Single table• No relations between tables, of course

Page 31: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

problem with this database

• All data wrong, but this is just for illustration.• Name covered inconsistently. There is no way

to find films by Woody Allan without having to go through all spelling variations.

• Mistakes are difficult to correct. We have to wade through all records, a masochist’s pleasure.

Page 32: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

Better movie databaseID | title |director | yearM1 | Gone with the wind | D1 | 1963M2 | Room with a view | D1 | 1985M3 | High Noon | D2 | 1974M4 | Star Wars | D3 | 1993M5 | Alien | D2 | 1987M6 | Blowing in the Wind | D3 | 1962

ID |director name | birth yearD1 | Ford Coppola, Francis | 1942D2 | Allan, Woody | 1957D3 | Spielberg, Steven | 1942

Page 33: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

Relational database

• We have a one to many relationship between directors and film– Each film has one director– Each director has produced many films

• Here it becomes possible for the computer– To know which films have been directed by Woody

Allen– To find which films have been directed by a

director born in 1942

Page 34: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

enforcing relationships

• Relational database software has ways to enforce relationships.

• So when you change the record of M5 to say it was directed by director D9, it will complain that no such director has been defined.

Page 35: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

Many-to-many relationships

• Each film has one director, but many actors star in it. Relationship between actors and films is a many to many relationship.

• Here are a few actorsID | sex | actor name | birth yearA1 | f | Brigitte Bardot | 1972A2 | m | George Clooney | 1927A3 | f | Marilyn Monroe | 1934

Page 36: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

Actor/Movie table

actor id | movie idA1 | M4A2 | M3A3 | M2A1 | M5A1 | M3A2 | M6A3 | M4

… as many lines as required

Page 37: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

relational databases

• Relational databases are powerful within organizations that have a relatively centralized command and control structure, i.e. within a company and / or a government department.

• The relational database model has problems when we are working in a coordinated fashion between several providers of information.

• Imagine the web working an a relational database model!

Page 38: LIS512 lecture 1 the entity-relationship model Thomas Krichel 2010-09-22

http://openlib.org/home/krichel

Thank you for your attention!

Please switch off machines b4 leaving!