CS134-lecture-20210602

DBMS cont. #

Database users #

image_2021-06-02-16-30-56

If we’re storing student information in a database, we’ll have fields such as

  • age
  • birthdate

If we want to store one in the database, which should we pick? Why only one?

We should choose the birthdate because

  • we can derive the age
  • birthdate is also more accurate of a measure of age
  • we won’t need to increment the age in the database every year

What is the disadvantage of saving both?

  • we don’t want to waste space when we can derive the age from the birthdate.
  • if we save both we have to make sure they are consistent. In other words: we would have to increment the age on the birthdate.

For end users:

  • casual end users: need to use a sophisticated database query language, like SQL
  • naive users: use a menu-driven interface
  • sophisticated end users: familiar with DBMS to implement their applications

Data models #

image_2021-06-02-16-41-38

High level models

  • ER, entity-relationship model, best for relational database
  • UML

Representational / implementation model

  • relational data model, uses relational database
  • object data model, O-O, O-R
  • network and hierarchical model, uses graph model

DBMS architecture and data independency #

image_2021-06-02-16-48-52

At the conceptual schema level, the user doesn’t necessarily know the exact implementation of the internal schema level.

Database languages #

image_2021-06-02-16-51-02

SQL is a comprehensive integrated language of DDL and DML for relational databases.

Entity-relationship model #

image_2021-06-02-16-56-12

Note: ER diagram notation can change based on different textbooks. We will use the original notation that is used in our text book.

Entity and attributes #

image_2021-06-02-16-58-12

Properties can be used to describe the entity. For example for a student:

image_2021-06-02-16-59-55 image_2021-06-02-17-00-37 image_2021-06-02-17-02-41 image_2021-06-02-17-03-00

On notation:

  • entities are in rectangles
  • attributes are circled and connected to the entity

image_2021-06-02-17-04-05

The divisibility of an attribute depends on application. We can divide address into subparts:

image_2021-06-02-17-06-19

Here, address is the composite attribute. Name can also be composite.

image_2021-06-02-17-08-34

image_2021-06-02-17-10-50

Students can only have 1 birthdate, but they can have multiple phone numbers. We can indicate that by a double circle.

image_2021-06-02-17-11-07

image_2021-06-02-17-13-37

Since age can be calculated from the birthdate, we can put the age attribute in the ER diagram, but we indicate it can be derived with a dashed line.

image_2021-06-02-17-15-10

image_2021-06-02-17-16-46

ER diagram notation #

image_2021-06-02-17-18-13

Keys #

image_2021-06-02-17-18-42

  • must be a unique identifier

We underline the attribute name to indicate that it is the key

image_2021-06-02-17-20-52

If we have an entity called classroom:

image_2021-06-02-17-23-06

We can use a composite key of the attributes building and roomNo.

image_2021-06-02-19-16-30

Keys must be minimal. In other words: adding capacity to the composite key for the classroom model wouldn’t add anything beneficial.

Value sets #

image_2021-06-02-19-21-21

ER diagram example #

image_2021-06-02-19-24-48 image_2021-06-02-19-28-01

Relationship #

image_2021-06-02-19-33-02

Relationships are drawn using a diamond.

image_2021-06-02-19-35-20 image_2021-06-02-19-36-36 image_2021-06-02-19-37-55

Structure constraint #

image_2021-06-02-19-38-37 image_2021-06-02-19-39-23 image_2021-06-02-19-40-41 image_2021-06-02-19-43-34 image_2021-06-02-19-45-01