Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules.

Slides:



Advertisements
Similar presentations
Relational Terminology. Normalization A method where data items are grouped together to better accommodate business changes Provides a method for representing.
Advertisements

Relational Database Design UNIT II 1. 2 Advantages of Using Database Systems Centralized control of a firm’s data Redundancy can be reduced (avoid keeping.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 5/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Relational Databases Relational Model Primary Keys Relation or Relationship Foreign Keys Relationships between entities Integrity Constraints Power of.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Fundamentals, Design, and Implementation, 9/e Chapter 5 Database Design.
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,
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
July 14, 2015ICS 424: recap1 Relational Database Design: Recap of ICS 324.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Define Table Relationships—1 of 3 One of the most powerful features of a relational database management system, such as Access, is its ability to define.
1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn 2013.
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.
Relational Model Session 6 Course Name: Database System Year : 2012.
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
Database Management COP4540, SCS, FIU Relational Model Chapter 7.
Fundamentals of Relational Database Yong Choi School of Business CSUB, Bakersfield.
Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I.
1 CSE 480: Database Systems Lecture 5: Relational Data Model.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Database Management System Lecture 4 The Relational Database Model- Introduction, Relational Database Concepts.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
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.
Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
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.
Defining NOT NULL and UNIQUE Constraints
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
Session 1 Module 1: Introduction to Data Integrity
Lecture 03 Constraints. Example Schema CONSTRAINTS.
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
The relational model1 The relational model Mathematical basis for relational databases.
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.
Lecture 4: Logical Database Design and the Relational Model 1.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Constraints Advanced Database Systems Dr. AlaaEddin Almabhouh.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
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.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
Chapter 71 The Relational Data Model, Relational Constraints & The Relational Algebra.
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.
Database Constraints Ashima Wadhwa. Database Constraints Database constraints are restrictions on the contents of the database or on database operations.
Getting started with Accurately Storing Data
Logical Database Design and the Rational Model
Chapter 5 Database Design
Chapter 4 Logical Database Design and the Relational Model
CIS 155 Table Relationship
Chapter 4 Relational Databases
Lecture # 13 (After 1st Exam)
Rules in active databases and integrity constraints
Chapter 3 The Relational Database Model
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Database solutions Chosen aspects of the relational model Marzena Nowakowska Faculty of Management and Computer Modelling Kielce University of Technology.
Design tools and techniques for a relational database system
INSTRUCTOR: MRS T.G. ZHOU
Presentation transcript:

Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules

Learning Outcome Understand and being able to identify primary, candidate and foreign keys. Grasp and being able to apply the data integrity rules of a relational database.

Terminology Primary Key An attribute or a set of attribute that enable data in a table to be uniquely identified. It is specified in table schema as a primary key.

Terminology- (Cont.) Candidate Key: An attribute or a set of attribute that enable data in a table to be uniquely identified. There could be more than Candidate Key in a table. However, one only can be specified as a primary key

Terminology (Cont.) Foreign Key: A set of attributes in table T1 that reference another set of corresponding primary key attributes in table T2. The foreign key attributes in T1 must have the same domain as the corresponding primary key attributes in T2

Primary Keys Having two identical rows in a table can cause data redundancy and inconsistency problems A primary key ensures that each row in a table unique with no duplicate It is an attribute or a set of attribute that enable data in a table to be uniquely identified

Primary Keys (Cont.) A table in a relational database must have a primary key.

Primary Keys (Cont.) For example, Consider a university library database which includes a student member table shown in Figure 6.1. The table has attributes such as name, phone number, matriculation number and department number

Primary Keys (Cont.) The student’s matriculation number can be used as a primary key as it can uniquely identify a student record. Attributes of a primary key are usually underlined.

Primary Keys (Cont.) The main characteristics of a primary key Must be minimal to avoid errors in data Must consist of attributes that can never have NULL values Must be fixed and should never be changed once the table is populated with data

Primary Keys (Cont.) Note that there could be more than one alternative attribute(s) that can uniquely identify rows in a table. Only one of them can be chosen to be the primary key. The other alternatives are called Candidate Keys

Matric NumberNamePhone NumberDepartment Number Ahmad Saleh Ameer Jabir Hamza Yussuf Student Member Table

Foreign Keys A foreign key is a set of attributes in table T1 that reference another set of corresponding primary key attributes in table T2. Foreign keys enable tables in a relational database to be linked together.

Foreign Keys (Cont.) The foreign key attributes in T1 must have the same domain as the corresponding primary key attributes in T2. Each value that occurs in the foreign key must also occur in the primary key.

Foreign Keys (Cont.) For example If a library database has two tables: student member and department shown in Figure 6.2. The student member table has primary key matriculation number and the department table has primary key department number.

Foreign Keys (Cont.) The two tables can be linked with each other using the department number attribute. Thus, department number in the student member table will be a foreign key linked to the department number attribute in the department table which is its primary key. Note that a foreign key is usually denoted by an asterisk (*).

Integrity Rules A Relational Database Management System (RDMS) enforces integrity rules to ensure the accuracy and accessibility of the data. Such rules govern which operations can be performed on the data In addition to putting constraints on the structure of the database

Integrity Rules (Cont.) There are three integrity rules that a relational database follow which are: 1. the Key Integrity rule, 2. the Entity Integrity rule 3. the Referential Integrity rule

The Key Integrity Rule The Key Integrity rule specifies that rows in a table must be unique with no row duplication. This is useful to remove any data ambiguity Thus, tables are defined as a unique set of rows with no two rows having the same combination of values for their attributes

The Key Integrity Rule (Cont.) Key constraints enforce this rule as follows (which we discussed earlier): Candidate Key: that is an attribute or a minimal combination of attributes that uniquely identify any row in a table. There could be more than one candidate key in a table.

The Key Integrity Rule (Cont.) Primary Key: is the candidate key chosen in the definition of the table schema to uniquely identify each row in the table.

The Entity Integrity Rule The Entity Integrity rule states that no attribute that is part of a primary key is allowed to have value NULL. If NULL values are allowed for primary key attributes, then two rows can have NULL as primary key values and thus the two rows can’t be uniquely identified

The Entity Integrity Rule (Cont.) This causes the Key Integrity rule to be violated. An illustration on how the Entity Integrity rule is shown in Figure 5.3 with the student member table having two rows with NULL values for the primary key attribute

The Referential Integrity Rule The Referential Integrity rule is concerned with the linking between tables using foreign keys. It states that an attribute in a table schema T1 is a foreign key if:

The Referential Integrity Rule (Cont.) 1. It has a relationship with a primary key in T2, 2. The domain of the foreign key in T1 is the same as the domain of the key in T2, and

The Referential Integrity Rule (Cont.) 3. The foreign key value in T1 must be equal to the value of T2’s primary key.

The Referential Integrity Rule (Cont.) Thus, the Referential Integrity rule ensures that any foreign key value is always pointing to a primary key row in the other table. References to non-existing primary keys are not allowed.

Enforcing the Integrity Rules Integrity rules must be checked whenever an operation is executed that updates the database. Three types of operations can violate the integrity rules which are: inserting a row, deleting a row and updating a row.

Examples of how Integrity rules can be violated Consider the library database shown in Figure 6.4 with the two tables student member and department

Adding the row below to the student member table would violate the Key Integrity rule and would not be allowed by the database. This is because there is already a row in the table with primary key value

Similarly, the row below would violate the Key Integrity rule as its primary key value is NULL.

Deleting the 3 rd row in the department table would violate the Referential Integrity rule as primary key value ‘121’ will be deleted. This will cause the foreign key in the 1 st row of the student member table to be invalid.

Similarly, updating the 3 rd row in the department table would be invalid as the foreign key in the 1 st row of the student member table will be pointing to a primary key with a different value.

Summary In this lesson, the following topics were discussed: Primary Keys. Foreign Keys. Integrity Rules. Enforcing the Integrity Rules.