1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn...

7
The relational model 1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn 2013

Transcript of 1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn...

Page 1: 1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn 2013.

The relational model

1

•Relational model concepts•Key constraints•Referential integrity constraint

Steen Jensen, autumn 2013

Page 2: 1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn 2013.

Relational model concepts, 1

The relational model represents the database as a collection of relations

Each relation resembles a table of values

The data type describing the possible values for each column (attribute) is represented by a domain of possible values, e.g. the data type for Age could be an integer number between 15 and 80

2

Figure 5.1 from chapt. 5 in Elmasri

Page 3: 1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn 2013.

Relational model concepts, 2

The above representation is also called a relation schema

The degree of a relation is the number of attributes of its relation schema – thus the relation STUDENT has a degree seven

Each value for a specific attribute is atomic - so composite and multivalued attributes are not allowed

The special value called NULL can be used, if the value is unknown or doesn’t apply

Some relations represent facts about entities and other relations represent facts about relationships

3

Page 4: 1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn 2013.

Key constraints

A relation schema may have more than one key – each of the keys is called a candidate key

One of the candidate keys is chosen as the primary key, so it is possible to identify tuples in the relation – thus a primary key can’t have a NULL value

The primary key is underlined

4

Page 5: 1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn 2013.

Referential integrity constraint, 1

Referential integrity is used to maintain the consistency among tuples in two relations

The referential integrity states, that a tuple in one relation that refers to another relation must refer to an existing tuple in that relation

To define referential integrity a foreign key is used

The relation in which the foreign key is placed is called the referencing relation, and the relation which the foreign key points to is called the referenced relation

The next slide shows an example of referential integrity

5

Page 6: 1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn 2013.

Referential integrity constraint, 2

6

Page 7: 1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn 2013.

Exercise in foreign keys Take a look at exercise 5.15 p. 165 in Elmasri chapter 5 (physical

page 26)

Make your solution in a format corresponding to the figure shown on the previous slide (approx. 30 minutes)1. Start by pairing up with the student next to you and suggest

the appropriate foreign keys

2. Share and discuss your solution with the other pair of students at your table

Finally the solution should be presented/discussed in class

7