Lecture 03 Constraints. Example Schema CONSTRAINTS.

Slides:



Advertisements
Similar presentations
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Advertisements

Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
The Relational Model Class 2 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) (From ER to Relational)
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
Relational Model Stores data as tables –Each column contains values about the same attribute –Each column has a distinct name –Each row contains values.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
5 Chapter 5 Structured Query Language (SQL1) Revision.
Data Integrity Constraints
The Relational Model Codd (1970): based on set theory Relational model: represents the database as a collection of relations (a table of values --> file)
Database Systems Relational Model Concepts Toqir Ahmad Rana Database Management Systems 1 Lecture 17.
CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E) 1.
Database Architecture The Relational Database Model.
Chapter 5 Relational Model Concepts Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 6: Integrity Objective Key Constraints (Chapter 2) Cardinality Constraints (Chapter 2) Domain Constraints Referential Integrity Assertions Triggers.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity and Security Domain Constraints Referential Integrity Assertions Triggers.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
The Relational Model These slides are based on the slides of your text book.
1 Lecture 04 The relational data Model, Relational Constraints 1.
Relational Model Session 6 Course Name: Database System Year : 2012.
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules.
Relational Data Model. A Brief History of Data Models  1950s file systems, punched cards  1960s hierarchical  IMS  1970s network  CODASYL, IDMS 
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints.
INTEGRITY. Integrity constraint Integrity constraints are specified on a database schema and are expected to hold on every valid database state of the.
1 The Relational Model Instructor: Mohamed Eltabakh
Topic 5 The Relational Data Model and Relational Database Constraints Faculty of Information Science and Technology Mahanakorn University of Technology.
Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 5 The Relational Data Model.
10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1 Week4 Relational Model and Relational Database Constraints Relational Model Concepts.
1 CSE 480: Database Systems Lecture 5: Relational Data Model.
METU Department of Computer Eng Ceng 302 Introduction to DBMS The Relational Data Model and Relational Database Constraints by Pinar Senkul resources:
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 The Basic Relational Model.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
Chapter 7 SQL: Data Definition Pearson Education © 2009.
1 CS 430 Database Theory Winter 2005 Lecture 4: Relational Model.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Chapter 3: Relational Databases
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
Mapping ER to Relational Model Each strong entity set becomes a table. Each weak entity set also becomes a table by adding primary key of owner entity.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Chapter 3 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints تنبيه.
Database Constraints ICT 011. Database Constraints Database constraints are restrictions on the contents of the database or on database operations Database.
Fundamental of Database Systems
Chapter 6: Integrity (and Security)
Lecture # 13 (After 1st Exam)
Constraints AND Examples
Rules in active databases and integrity constraints
Referential Integrity
Referential Integrity
INSTRUCTOR: MRS T.G. ZHOU
Database Dr. Roueida Mohammed.
Relational Data Model - 2
Constraints AND Examples
Presentation transcript:

Lecture 03 Constraints

Example Schema

CONSTRAINTS

Constraints Constraints are restrictions on legal relation states – they add further semantics to the schema Domain constraints – values for an attribute must be from the domain associated with the attribute Non-null constraints – the domain of some attributes may not include null, implying that a value for that attribute is required for all tuples v i є dom(A i )

Key Constraints By definition, all tuples in a relation are unique Often, we want to restrict tuples further such that some subset of the attributes is unique for all tuples Example: in the StockItem relation, no ItemID should appear in more than one tuple – ItemID is called a key attribute

Keys and Superkeys Any subset of attributes that must be unique is called a superkey Example: VEHICLE(LicenseNumber, SerialNumber, Model, Year) key superkey key

Candidate and Primary Keys If a relation has more than one key, each key is called a candidate key One candidate key must be chosen to be the primary key The primary key is the one that will be used to identify tuples If there is only one key, it is the primary key

Candidate and Primary Keys Primary keys are indicated by underlining the attributes that make up that key VEHICLE(LicenseNumber, VIN, Model, Year) candidate key primary key candidate key

Integrity Constraints Entity integrity constraint – no primary key value can be null – the primary key is the tuple identifier Referential integrity constraint – references between relations must be valid – the foreign key of a referencing relation must exist as a primary key in the referenced relation

Referential Integrity PK = primary key in R 2 FK = foreign key in R 1 dom(R 1 [FK]) = dom(R 2 [PK]) constraint: if v є R 1 [FK] then v є R 2 [PK] note: FK is not necessarily a key of R 1

Schema with FKs

STATE CHANGE AND CONSTRAINT ENFORCEMENT

Causes of Constraint Violations What can cause a referential integrity constraint violation? – inserting a tuple in R 1 with an illegal FK – modifying a tuple in R 1 to have an illegal FK – deleting a tuple in R 2 that had the PK referenced by some FK in R 1 How can a referential integrity constraint be enforced? – reject the operation that attempts to violate it (may cause other operations to be rejected … transactions) or – repair the violation, by cascading inserts or deletes

Data Manipulation Operations There are three ways to modify the value of a relation: Insert: add a new tuple to R Delete: remove an existing tuple from R Update: change the value of an existing tuple in R Delete and Update both require some way to identify an existing tuple (a selection)

Enforcing Constraints constraint enforcement: ensuring that no invalid database states can exist invalid state: a state in which a constraint is violated Possible ways to enforce constraints: – reject any operation that causes a violation, or – allow the violating operation and then attempt to correct the database

Summary: Relational Schemas A relational schema consists of a set of relation schemas and a set of constraints Relation schema – list of attributes: name and domain constraint – superkeys: key constraints – primary key: entity integrity constraint Foreign keys: referential integrity constraints – defined between relation schemas

Schema for Airline Database