Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to Data Management: Lecture 16, Lecture notes of Database Management Systems (DBMS)

A set of lecture notes from CSE 344, a course on data management. The lecture focuses on constraints in E/R diagrams and SQL. The notes cover topics such as weak entity sets, key constraints, and foreign key constraints. The document also includes examples of updates and the types of constraints used in modeling. The notes are from Fall 2013 and include announcements for the class.

Typology: Lecture notes

2012/2013

Uploaded on 05/11/2023

shokha
shokha 🇮🇳

4.5

(13)

234 documents

1 / 35

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Introduction to Data Management
CSE 344
Lecture 16: Constraints
CSE 344 - Fall 2013 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23

Partial preview of the text

Download Introduction to Data Management: Lecture 16 and more Lecture notes Database Management Systems (DBMS) in PDF only on Docsity!

Introduction to Data Management

CSE 344

Lecture 16: Constraints

Announcements

  • WQ6 due Thursday (there is no WQ5…)
  • Homework 4 posted, due Friday
  • Midterm: Monday, November 4 th

, in class

Where We Are?

We are learning about database design

  • How to design a database schema?
  • Last time: Real world -> ER Diagrams -> Relations Next, we will learn more about good schemas
  • Today: Constraints and data integrity
  • Next time: Schema normalization, then Views

Person Company Product buys makes employs name CEO price address name ssn address name 5

Weak Entity Sets

Team University affiliation sport number name Team(sport, number, universityName) University(name) What does this say?

What Are the Keys of R?

R

A B S T V Q

W U

V

Z

C

D

E

G

K

H

F

L

Constraints in E/R Diagrams

Finding constraints is part of the modeling process. Commonly used constraints: Keys: social security number uniquely identifies a person. Single-value constraints: a person can have only one father. Referential integrity constraints: if you work for a company, it must exist in the database. Other constraints: peoples’ ages are between 0 and 150.

Keys in E/R Diagrams

address name ssn Person Product name category price No formal way to specify multiple keys in E/R diagrams Underline: 11

Referential Integrity Constraints

Product Company makes Product Company makes Each product made by at most one company. Some products made by no company Each product made by exactly one company.

Other Constraints

Product Company makes

Q: What does this mean? A: A Company entity cannot be connected by relationship to more than 99 Product entities

Key Constraints

OR:

CREATE TABLE Product ( name CHAR(30) PRIMARY KEY, category VARCHAR(20)) CREATE TABLE Product ( name CHAR(30), category VARCHAR(20) PRIMARY KEY (name)) Product(name, category)

Keys with Multiple Attributes

CREATE TABLE Product ( name CHAR(30), category VARCHAR(20), price INT, PRIMARY KEY (name, category)) Name Category Price Gizmo Gadget 10 Camera Photo 20 Gizmo Photo 30 Gizmo Gadget 40 Product(name, category, price)

Foreign Key Constraints

CREATE TABLE Purchase ( prodName CHAR(30) REFERENCES Product(name), date DATETIME) prodName is a foreign key to Product(name) name must be a key in Product Referential integrity constraints May write just Product if name is PK

Name Category Gizmo gadget Camera Photo OneClick Photo ProdName Store Gizmo Wiz Camera Ritz Camera Wiz Product Purchase

Foreign Key Constraints