CS134-lecture-20210608

RE assignment 1 #

account_number is a unique value.

Relational model cont. #

State cont. #

image_2021-06-08-16-14-58

R(color, bit)
dom(color) = {blue, green, red}
dom(bit)   = {0, 1}
color bit
blue 0
blue 1
green 0
green 1
red 0
red 1

This is all the possible combinations, but lets say we have a state like

color bit
blue 1
green 0

Which visualizes that the state is a subset of all possible combinations.

Specifying an attribute’s value #

image_2021-06-08-16-23-38

Constraints #

image_2021-06-08-16-22-51

As a programmer we don’t have much of selection when it comes to model-based constraints.

image_2021-06-08-16-22-58

DDL = data definition language

Note: We are not currently covering data dependencies.

image_2021-06-08-16-37-49 image_2021-06-08-16-38-40

Key constraints #

image_2021-06-08-16-39-11

Versus a key, superkeys do not have to be minimal.

image_2021-06-08-16-49-17

  • {ssn, name} is a superkey
  • {building, room_no} is a key, and a superkey

True or false

  • Any superkey is a key
    • false
  • Any key is a superkey
    • true

Primary key #

image_2021-06-08-16-59-41

We have two candidate keys license_number and engine_serial_number. We will need to pick 1 to be the primary key.

image_2021-06-08-17-00-18

Note on notation in relational model: we only underline the primary key.

Constraints on null values #

image_2021-06-08-17-03-55

Entity integrity constraint #

image_2021-06-08-17-07-14

Multiple relations – referential integrity constraints #

image_2021-06-08-17-08-46

Foreign keys #

image_2021-06-08-17-11-11

Foreign keys can be

  • 1 attributes
  • or, \( n \) attributes

The foreign key must

  • have the same domain as the primary keys on the other schema.
  • obey t1[foreign] = t2[primary]

image_2021-06-08-17-15-00 image_2021-06-08-17-15-20

DNO \( \to \) DNUMBER is a foreign key with 1 attribute

image_2021-06-08-17-18-52

Remember, to be a foreign key, we need to verify that DNO and DNUMBER have the same domain. They do not have to have the same name.

If we change the requirement so that employees don’t have to work for a department, the keys must reference to existing attributes:

image_2021-06-08-17-21-41

But if we have an employee that doesn’t have a department, we must put a null value:

image_2021-06-08-17-22-00

Another example of a foreign key:

image_2021-06-08-17-24-42

Notice that foreign keys create duplication among tuples.

image_2021-06-08-17-28-17 image_2021-06-08-18-00-50

Application based constraints #

image_2021-06-08-18-09-29

Triggers and assertions are part of SQL.