Docsity

Transforming E-R Schemas into Relational Database Schemas and Relational Algebra - Prof. M, Study notes of Computer Science

Partial preview of the text

Download Transforming E-R Schemas into Relational Database Schemas and Relational Algebra - Prof. M and more Study notes Computer Science in PDF only on Docsity!

What you should have learned after this lecture ... ย‰ how an E-R schema is transformed into a relational database schema ย‰ what relational algebra^ is and what its main basic operations are

Transformation of a 1: m - and a^ m :1-relationship set ย‰^ For each binary 1: m -relationship set

R^ let^ S^ be the relation schema which corre- sponds to the entity set participating in

R^ on the^ m -side. Add to^ S^ as foreign key the primary key of relation schema^ T , which corresponds to the other entity set participat-ing in^ R. The reason for this is that each entity on the

m -side is associated with at most one entity on the 1-side of^ R

. Furthermore, all simple attributes and all simple components of composite attributes of

R^ are taken as attributes of^ S. ย‰^ example university data base:lectures(id, credits, title, held_by)professors(pers-id, name, room, rank)assistants(pers-id, name, room, boss) ย‰^ The names of attributes of a foreign key have partially to be changed in order toensure the uniqueness of names in a schema.

Transformation of an^ n -ary relationship set ย‰^ For each^ n -ary relationship set^

R^ with^ n^ > 2 a new relation schema

S^ is created. Add to^ S^ as foreign keys the primary keys of the relation schemas corresponding to entitysets participating in^ R. Furthermore, all simple attributes and all simple componentsof composite attributes of^ R^ are taken as attributes of

S. The primary key of^ S^ is the combination of all foreign keys. ย‰ example university database:tests(reg-id, id, pers-id, grade)Complete schema of the university databasestudents(reg-id :^ integer , name :^ string

, sem :^ integer ) lectures(id :^ integer , credits :^ integer

, title :^ string , held_by :^ integer ) professors(pers-id :^ integer , name :

string , room :^ integer , rank :^ string ) assistants(pers-id :^ integer , name :^

string , room :^ integer , boss :^ integer

attends(reg-id :^ integer , id :^ integer ) is_precondition_of(predecessor :^ integer

, successor :^ integer ) tests(reg-id :^ integer , id :^ integer , pers-id :

integer , grade :^ integer )

Transformation of generalizations ย‰^ Generalizations are not represented by an own relation. The relationship is alreadyexpressed by the fact that the key of the common superclass is also used as key ofthe specialized subclasses. ย‰^ example: employees(pers-id, name, room)professors(pers-id, rank)assistants(pers-id) ย‰^ information about a professor distributed to two tuples of two relations, namely to atuple of the relation^ employees^

and to a tuple of the relation^ professors ย‰^ To obtain the complete information requires a connection of both relations and tuples,respectively (join). There is no inheritance in the relational data model.

employees^ pers-idroomname^ is-a rank assistants^ professors^

ย‰^ relational algebra is a universal algebra^ โˆ’^ anchor is the set of all relations^ โˆ’^ 5 (+ 1) basic operations:^ union

,^ difference ,^ Cartesian product ,^ project

,^ select , ( rename ) โˆ’ other algebra operations are derived, i.e., they can be expressed by the basicoperations ย‰ given: two relations^ R ( A :^ C ,^ A :^ C^1 12

, ...,^ A :^ C^ ) and^ S ( B :^ D ,^ B :^ D , ..., r^ r^1 12

B :^ D ) s^ s with arity^ r^ and^ s ย‰ R^ and^ S^ are^ schema compliant^ (identical except for renaming), if

r^ =^ s^ holds and if there exists a permutation^ ฯ•^ of the indices {1, ...,

r }, so that^ โˆ€^1 โ‰ค^ i^ โ‰ค^ r^ :^ C^ =^ Di^ ฯ•( i ) The Union operation ย‰^ R^ and^ S^ are schema compliant ย‰^ R^ โˆช^ S^ = { t^ |^ t^ โˆˆ^ R^ โˆจ^ t^ โˆˆ^ S } The Difference operation ย‰^ R^ and^ S^ are schema compliant ย‰^ R^ โˆ’^ S^ = { t^ |^ t^ โˆˆ^ R^ โˆง^ t^ โˆ‰^ S }