Relational Database Constraints

Similar documents
The Relational Data Model and Relational Database Constraints

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

The Relational Data Model: Structure

Relational model. Relational model - practice. Relational Database Definitions 9/27/11. Relational model. Relational Database: Terminology

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model

CS 377 Database Systems. Database Design Theory and Normalization. Li Xiong Department of Mathematics and Computer Science Emory University

Data Modeling. Database Systems: The Complete Book Ch ,

Relational Schema Design

Chapter 10 Functional Dependencies and Normalization for Relational Databases

Database Design Methodology

Entity-Relationship Model

AVOIDANCE OF CYCLICAL REFERENCE OF FOREIGN KEYS IN DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL

COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model

Databasesystemer, forår 2005 IT Universitetet i København. Forelæsning 3: Business rules, constraints & triggers. 3. marts 2005

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

ER modelling, Weak Entities, Class Hierarchies, Aggregation

ER & EER to Relational Mapping. Chapter 9 1

EECS 647: Introduction to Database Systems

Theory of Relational Database Design and Normalization

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

IT2304: Database Systems 1 (DBS 1)

A Tool for Generating Relational Database Schema from EER Diagram

MCQs~Databases~Relational Model and Normalization

We know how to query a database using SQL. A set of tables and their schemas are given Data are properly loaded

Chapter 3. Data Modeling Using the Entity-Relationship (ER) Model

Converting E-R Diagrams to Relational Model. Winter Lecture 17

How To Manage Data In A Database System

Chapter 2: Entity-Relationship Model

Database Design Methodology

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Lesson 8: Introduction to Databases E-R Data Modeling

Databases and BigData

IT2305 Database Systems I (Compulsory)

Lecture 6. SQL, Logical DB Design

2. Conceptual Modeling using the Entity-Relationship Model

Chapter 2: Entity-Relationship Model. Entity Sets. " Example: specific person, company, event, plant

Chapter 6: Integrity Constraints

A. TRUE-FALSE: GROUP 2 PRACTICE EXAMPLES FOR THE REVIEW QUIZ:

Information Systems Modelling Information Systems I: Databases

The Entity-Relationship Model

1 Class Diagrams and Entity Relationship Diagrams (ERD)

Database Design. Adrienne Watt. Port Moody

Fundamentals of Database Design

Normalization in Database Design

not necessarily strictly sequential feedback loops exist, i.e. may need to revisit earlier stages during a later stage

Chapter 2: Entity-Relationship Model. E-R R Diagrams

Concepts of Database Management Seventh Edition. Chapter 6 Database Design 2: Design Method

THE ENTITY- RELATIONSHIP (ER) MODEL CHAPTER 7 (6/E) CHAPTER 3 (5/E)

Databases What the Specification Says

Relational Database Concepts

Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design

RELATIONSHIP STRENGTH

Physical Database Design Process. Physical Database Design Process. Major Inputs to Physical Database. Components of Physical Database Design

XV. The Entity-Relationship Model

Relational Database Basics Review

Chapter 10. Functional Dependencies and Normalization for Relational Databases

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Review: Participation Constraints

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

A brief overview of developing a conceptual data model as the first step in creating a relational database.

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Conceptual Design Using the Entity-Relationship (ER) Model

Rose Data Modeler (logical)

Data Analysis 1. SET08104 Database Systems. Napier University

CPS352 Database Systems: Design Project

Modern Systems Analysis and Design

CIS 631 Database Management Systems Sample Final Exam

CSC 443 Fall 2011 Dr. R. M. Siegfried. Answers to Assignment #1

Unit 2.1. Data Analysis 1 - V Data Analysis 1. Dr Gordon Russell, Napier University


SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Chapter 4. Entity: an object that is involved in the enterprise

SQL NULL s, Constraints, Triggers

Normal Form vs. Non-First Normal Form

The Relational Model. Why Study the Relational Model?

CSC 742 Database Management Systems

Database Systems. Session 3 Main Theme. Enterprise Data Modeling Using The Entity/Relationship (ER) Model. Dr. Jean-Claude Franchitti

DATABASE INTRODUCTION

Chapter 5: Logical Database Design and the Relational Model Part 2: Normalization. Introduction to Normalization. Normal Forms.

DATABASE DESIGN. - Developing database and information systems is performed using a development lifecycle, which consists of a series of steps.

Relational Databases

Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases

COSC344 Database Theory and Applications. Lecture 9 Normalisation. COSC344 Lecture 9 1

Scheme G. Sample Test Paper-I

Database IST400/600. Jian Qin. A collection of data? A computer system? Everything you collected for your group project?

Lecture 12: Entity Relationship Modelling

Lecture Notes INFORMATION RESOURCES

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

Database Design for the Uninitiated CDS Brownbag Series CDS

Logical Schema Design: The Relational Data Model

3. Relational Model and Relational Algebra

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

Performance Evaluation of Natural and Surrogate Key Database Architectures

BCA. Database Management System

Database Design and the E-R Model

Transcription:

Relational Database Constraints Chapter 3 b Chapter Outline Relational integrity constraints Key constraints Entity integrity Referential integrity it Other types of constraints Example ER to Relational mapping algorithm 1

Relational Integrity Constraints Constraints are conditions that must hold on all valid relation instances. There are three main types of constraints: 1. Key constraints 2. Entity integrity constraints 3. Referential integrity constraints Key Constraints Superkey of R: A set of attributes SK of R such that no two tuples in any valid relation instance r(r) will have the same value for SK. That is, for any distinct tuples t1 and t2 in r(r), t1[sk] t2[sk]. Key of R: A "minimal" superkey; that is, a superkey K such that removal of any attribute from K results in a set of attributes t that t is not a superkey. 2

Key Constraints II Example: The CAR relation schema: CAR(Label, Reg#, SerialNo, Make, Model, Year) has two keys Key1 = {Label, Reg#}, Key2 = {SerialNo}, which are also superkeys. {SerialNo, Make} is a superkey but not a key. If a relation has several candidate keys, one is chosen arbitrarily to be the primary key. The primary key attributes are underlined. Entity Integrity Relational Database Schema: A set S of relation schemas that t belong to the same database. S is the name of the database. S = {R 1, R 2,..., R n } Entity Integrity: The primary key attributes PK of each relation schema R in S cannot have null values in any tuple of r(r). This is because primary key values are used to identify the individual tuples. t[pk] null for any tuple t in r(r) 3

Referential Integrity A constraint involving two relations (the previous constraints involve a single relation). Used to specify a relationship among tuples in two relations: the referencing relation and the referenced relation. Tuples in the referencing relation R 1 have attributes FK (called foreign key attributes) that reference the primary key attributes PK of the referenced relation R 2. A tuple t 1 in R 1 is said to reference a tuple t 2 in R 2 if t 1 [FK] = t 2 [PK]. A referential integrity constraint can be displayed in a relational database schema as a directed arc from R 1.FK to R 2. Referential Integrity II Statement of the constraint The value in the foreign key column(s) FK of the referencing relation R 1 can be either: 1. a value of an existing primary key value of the corresponding primary key PK in the referenced relation R 2,, or. 2. a null. In case (2), the FK in R 1 should not be a part of its own primary key. 4

Other Types of Constraints Semantic Integrity Constraints: - based on application semantics and cannot be expressed by the model - E.g., the max. no. of hours per employee for all projects he on is 56 hrs per week - A constraint t specification language may have to be used to express these - SQL-99 allows triggers and ASSERTIONS Example 5

STEP 1: For each regular (strong) entity type E in the ER schema, create a relation R that includes all the simple attributes of E STEP 2: For each weak entity W with owner entity E, create a relation R, and include all simple attributes of W as attributes of R. In addition, include as foreign key attributes of R the primary key attribute(s) of the relation(s) that correspond to the owner entity type(s); 6

STEP 3: For each binary 1:1 relationship R in the ER schema, identify the relations S and T that correspond to the entity types participating in R. Choose one of the relations S, say and include as foreign key in S the primary key of T. It is better to choose an entity type with total participation in R in the role of S. Include all the simple attributes of the 1:1 relationship type R as attributes of S STEP 4: For each regular binary 1:N relationship R, identify the relation S that represents the participating entity type at the N-side of the relationship. Include as foreign key in S the primary key of the relation T that represents the other entity participating in R. Include any simple attributes of the 1:N relationship type as attributes of S. 7

STEP 5: For each binary M:N relationship R, create a new relation S to represent R. Include as foreign key attributes in S the primary keys of the relations that represent the participating entity; their combination will form the primary key of S. include any simple attributes of the M:N relationship as attributes of S. STEP 6: For each multivalued attribute A, create a new relation R. This relation R will include an attribute corresponding to A, plus the primary key attribute K as a foreign key in R of the relation that represents the entity or relationship that has A as an attribute. The primary key of R is the combination of A and K. If the multivalued attribute is composite, we include its simple components 8

STEP 7: For each n-ary relationship R, where n > 2, create a new relation S to represent R. Include as foreign key attributes in S the primary keys of the relations that represent the participating entity. Also include any simple attributes of the n-ary relationship type as attributes of S. The primary key of S is usually a combination of all the foreign keys that reference the relations representing the participating entity types. ER vs.relational ER Model Relational Model Entity type "Entity" relation 1:1 or 1:N relationship type Foreign key (or "relationship" relation) M:N relationship type "Relationship" relation and two foreign keys n-ary relationship type "Relationship" relation and n foreign keys Simple attribute Attribute Composite attribute Set of simple component attributes Multivalued attribute Relation and foreign key Value set Domain Key attribute Primary (or secondary) key 9