You are on page 1of 3

1/20/2018 From Class Diagram to Relation Schema

Creating Databases

From Class Diagram to Relation


Schema
Before you can define the database tables using a specific database
management software and DDL (Data Definition Language), you must
write a relation shema for each table. The set of relation schemas form
the relational database schema which is used as input when defining the
database.

Car Rental Database

There is a class diagram of the Car Rental database below. This diagram
has been drawn using UML classes and associations. The name of the
entity is in the upper box. The attributes for the entity are written in the
lower box. The primary key candidates are underlined.

Picture 1. The Class Diagram of the Car Rental database A customer has
made one or more (1..*) car rentals. A certain car rent always belongs to
a certain customer (1) and there is always a specific car (1) that is
rented. A car is rented out several times. If the car is a new one, it might
not be rented out yet (0..*). A car has a certain car type (1). There is at
least one car in each car type (1..*). In the class diagram datatypes can
be written. It might be a good idea to think about datatypes at this point.
You have to define the datatype for each attribute before you can
implement the database.

In picture 2 there are datatypes defined in the class diagram.

http://www2.amk.fi/digma.fi/www.amk.fi/opintojaksot/0303011/1146161367915/1146161783414/1146163048742/1146163155917.html 1/3
1/20/2018 From Class Diagram to Relation Schema

Picture 2. Class diagram with datatypes.

The relation schemas for the Car Rental database are:

Relation Schema

A relation schema is a named relation defined by a set of attributes (see


the Car Rental relation shemas above).

A relation has the following properties:


- a relation has a name that is distinct from all other relation names in
the relational database schema
- each attribute in one relation has a distinct name
- each tuple is distinct, there are no duplicate tuples
- the order of the attribures has no significance.

The name of the relation is written with capital letters. The primary key is
underlined and foreign keys are in italics.

Teacher and Courses

A teacher has one or more courses to teach (1..*). A certain course is


lectured by several teachers. If the course is a new one, it may not have
been lectured yet (0..*). The diagram is below. There is a many-to-many
relationship between a teacher and a course.

http://www2.amk.fi/digma.fi/www.amk.fi/opintojaksot/0303011/1146161367915/1146161783414/1146163048742/1146163155917.html 2/3
1/20/2018 From Class Diagram to Relation Schema

Picture 3. Teacher and courses.

For this kind of relationship you must define a new relation between the
two existing relations. This will split the many-to-many relationship to two
one-to-many relationships. In the new relation there are the primary keys
of the existing entities. Note how the primary keys are formed.

The relation schema for teachers and courses is:

If you have to save the year and the semester of the course that a
teacher is lecturing, the class diagram will be:

Picture 4. Teacher, courses and implementation data

The relation schema for this diagram is defined (note where the year and
semester are to be written):

Authors More info

http://www2.amk.fi/digma.fi/www.amk.fi/opintojaksot/0303011/1146161367915/1146161783414/1146163048742/1146163155917.html 3/3

You might also like