Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I.

Slides:



Advertisements
Similar presentations
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
Advertisements

Relational Model dww-database system.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
Chapter 5 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Database Systems Chapter 5 ITM 354. Chapter Outline Relational Model Concepts Relational Model Constraints and Relational Database Schemas Update Operations.
Chapter 5 The Relational Data Model and Relational Database Constraints.
Database Systems Relational Model Concepts Toqir Ahmad Rana Database Management Systems 1 Lecture 17.
Chapter 5 Relational Model Concepts Dr. Bernard Chen Ph.D. University of Central Arkansas.
Exam 2 Review Dr. Bernard Chen Ph.D. University of Central Arkansas.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
Chapter 4 The Relational Model Pearson Education © 2014.
Relational Model Session 6 Course Name: Database System Year : 2012.
The Relational Data Model 1.Relational Model Concepts 2.Characteristics of Relations 3.Relational Integrity Constraints 3.1Key Constraints 3.2Entity Integrity.
1 The Relational Data Model, Relational Constraints, and The Relational Algebra.
Chapter 4 Rational data model. Chapter 5 Rational data model Chapter 4 Rational data model.
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and SQL.
Topic 5 The Relational Data Model and Relational Database Constraints Faculty of Information Science and Technology Mahanakorn University of Technology.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 5 The Relational Data Model.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
The Relational Data Model and Relational Database Constraints
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1 Week4 Relational Model and Relational Database Constraints Relational Model Concepts.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
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:
Ihr Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
Chapter 6 The Relational Data Model and the Relational Algebra.
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.
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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
Relational Data Model DeSiaMore Powered by DeSiaMore.
Chapter 5 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
1 CSBP430 – Database Systems Chapter 7 - The Relational Data Model Elarbi Badidi College of Information Technology United Arab Emirates University
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 5 The Relational Data Model and Relational Database Constraints Slide 1- 1.
The Relational Data Model and Relational Database Constraints
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
The Relational Data Model and Relational Database Constraints.
4/28/2017 Chapter 5 The Relational Data Model and Relational Database Constraints.
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 تنبيه.
Copyright © 2004 Pearson Education, Inc.
4/20/2018.
Lecture # 13 (After 1st Exam)
The Relational Data Model
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
CS4222 Principles of Database System
12/7/2018.
The Relational Data Model and Relational Database Constraints
2/28/2019 Chapter 5 The Relational Data Model and Relational Database Constraints.
4/8/2019.
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
5/12/2019.
Copyright © 2004 Pearson Education, Inc.
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
Presentation transcript:

Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I

Outlines 1) Relational Database 2) Relational Data Model 3) Relational Database Constraints and Relational Database Schemas 4) Update Operations on Relations 5) Relational Algebra

Relational Database  Definition (by C.J. Date) “ A relational database is a database that is perceived by its users as a collection of tables. It is not just a database in which the data is physically stored as tables. ” Note: Relation is a mathematical term for a table.

Relational Data Model  The relational model of data is based on the concept of a Relation.  A relation is a mathematical concept based on the ideas of sets.  The strength of the relational approach to data management comes from the formal foundation provided by the theory of relations.  We review the essentials of the relational approach in this chapter.  Concepts

Relational Data Model RELATION: A table of values  What is “Relation” ?  Each column typically is called by its column name or column header or attribute name.  Sometimes row-ids or sequential numbers are assigned to identify the rows in the table.  Each row has a value of an item or set of items that uniquely identifies that row in the table.  Each row represents a fact that corresponds to a real-world entity or relationship.  A relation may alternately be thought of as a set of columns.  A relation may be thought of as a set of rows.

Relational Data Model  A relation is a named, 2-dimentional table of data. Not all tables qualify as relation.  Relation properties  Every relation has a unique name.  Each column has a unique name.  No 2 rows are identical.  Ordering of rows is not significant.  Ordering of columns is not significant.  All attribute values are atomic. (There always exists precisely one value, never a set of values)  Column values are of the same kind.

Relational Data Model  For Example: CUSTOMER (Cust-id, Cust-name, Address, Phone#)  Relation schema R (A 1, A 2,.....A n ) R is the name of relation. Degree of relation is the numbers of attributes of its relation schema. Relation schema R is defined over attributes A 1, A 2,.....A n CUSTOMER is a relation defined over the four attributes Cust-id, Cust-name, Address, Phone#, each of which has a domain or a set of valid values. Degree of relation is 4.

Relational Data Model  For Example: Cust-id : The set of valid 6-digit numbers. Cust-name : The set of customer names. Address : The set of home address where customers live. Phone# : The set of 10-digit phone numbers valid in Thailand.  Domain “ A domain D is a set of atomic values, all of the same type. ” All values in a column come from the same domain.

Relational Data Model  A domain has a logical definition. e.g., “USA_phone_numbers” are the set of 10 digit phone numbers valid in the U.S.  A domain may have a data-type or a format defined for it. e.g., The USA_phone_numbers may have a format: (ddd)-ddd-dddd where each d is a decimal digit. e.g., Dates have various formats such as monthname, date, year or yyyy-mm-dd, or dd mm,yyyy etc.  An attribute designates the role played by the domain. e.g., The domain Date may be used to define attributes “Invoice-date” and “Payment-date”.  Domain (Continued)

Relational Data Model  Each attribute in the model should be assigned domain information which includes: - Data type - Length - Data format (e.g., Date format is dd/mm/yy) - Range - Constraints (special restrictions on allowable values) - Null support - Default value (if any)  Domain (Continued)

Relational Data Model  A relation instance, r, of the relation schema  Relation instance R (A 1, A 2,.....A n ), denoted by r(R) is a mathematical relation of degree n on the domains dom(A 1 ), dom(A 2 ),…, dom(A n ), which is the subset of the Cartesian Product of the domains that define R. R is also called the intension of a relation. r is also called the extension of a relation.

Relational Data Model  A tuple is an ordered set of values.  Tuple  Columns in a table are also called attributes of the relation.  A relation may be regarded as a set of tuples (rows).  is a tuple belonging to the CUSTOMER relation.  Each row in the CUSTOMER table may be referred to as a tuple in the table and would consist of four values.  Each value is derived from an appropriate domain.

Relational Data Model We refer to component values of a tuple t by t[A i ] = v i (the value of attribute A i for tuple t). Similarly, t[A u, A v,..., A w ] refers to the subtuple of t containing the values of attributes A u, A v,..., A w, respectively.  Tuple (Continued)

Relational Data Model  Let S 1 = {0,1}  Let S 2 = {a,b,c}  Let  Then for example: is one possible ‘state’ or ‘population’ or ‘extension’ r of the relation R, defined over domains S 1 and S 2. It has three tuples.

Relational Data Model  Terminology Formal TermsInformal Terms RelationTable Attribute/DomainColumn TupleRow DomainValues in a column or pool of legal values Schema of a relationTable definition ExtensionPopulated table DegreeNo. of columns CardinalityNo. of rows Primary keyUnique identifier

Relational Data Model  Example

Relational Data Model  Key fields  Keys are special fields that serve two main purposes: - Primary keys are unique identifiers of the relation. Examples can use SSN as a primary key. This is how we can guarantee that all rows are unique. - Foreign key is a column or columns whose values are the same as a primary key of another table.  Keys can be simple (a single field) or composite (more than one field)  Keys usually are used as indexes to speed up the response to user queries.

Relational Constraints  There are three main types of constraints: “ Constraints are conditions that must hold on all valid relation instances. ” (Elmasri&Navathe, 2000)  Key constraints  Entity integrity constraints  Referential integrity constraints  What are relational constraints? “ Restrictions on data that can be specified on a relational database schema. ” (Date, 2000)

Relational 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 t 1 and t 2 in r(R), t 1 [SK]  t 2 [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 that is not a superkey.  Example: The CAR relation schema: CAR(State, Reg#, SerialNo, Make, Model, Year) has two keys Key1 = {State, Reg#}, Key2 = {SerialNo}, which are also superkeys. {SerialNo, Make} is a superkey but not a key.

Relational Constraints  Key constraints (Continued) The CAR relation with two candidate keys: LicenseNumber and EngineSerialNumber.

Relational Constraints  Key constraints (Continued)  A relation schema may have more than 1 key. Each of the keys is called a candidate key. One of the candidate keys are designated as the primary key of the relation.  If a relation has several candidate keys, one is chosen arbitrarily to be the primary key. The primary key attributes are underlined.

Relational Constraints  Entity integrity constraints  Relational Database Schema: A set S of relation schemas that 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)  Note: Other attributes of R may be similarly constrained to disallow null values, even though they are not members of the primary key.

Relational Constraints  Entity integrity constraints (Continued)  A Null is created by making no entry at all, so a null denotes the absence of a value. - The value does not exist - The value exists, but it is not known. - The value is unknown, or it is not applicable.  A null can have any of the following meanings:

Relational Constraints  Referential integrity constraints  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.

Relational Constraints  Referential integrity constraints (Continued)  Statement of the constraint The value in the foreign key column (or columns) FK of the 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.

Relational Constraints  Referential integrity constraints displayed on the COMPANY relational database schema

Relational Constraints Key constraints (columns) Entity integrity constraints (rows) Referential integrity constraints (between tables)  Summary of relational constraints

Update Operations on Relations  UPDATE operations consist of: INSERT a tuple DELETE a tuple MODIFY a tuple  Integrity constraints should not be violated by the update operations.  Several update operations may have to be grouped together.  Updates may propagate to cause other updates automatically. This may be necessary to maintain integrity constraints.

Update Operations on Relations  In case of integrity violation, several actions can be taken:  Cancel the operation that causes the violation (REJECT option)  Perform the operation but inform the user of the violation  Trigger additional updates so the violation is corrected (CASCADE option, SET NULL option)  Execute a user-specified error-correction routine e

Update Operations on Relations  Insert operation  Insert into EMPLOYEE. This insertion violates the entity integrity constraint (null for the primary key SSN), so it is rejected.  Insert into EMPLOYEE. This insertion satisfies all constraints, so it is acceptable.

Update Operations on Relations  Delete operation  Delete the WORKS_ON tuple with ESSN = ‘ ’ and PNO = 10. This deletion is acceptable.  Delete the EMPLOYEE tuple with SSN = ‘ ’ This deletion is not acceptable, because tuples in WORKS_ON refer to this tuple. Hence, if the tuple is deleted, referential integrity violations will result.

Update Operations on Relations  Modify/Update operation  Update the SALARY of the EMPLOYEE tuple with SSN = ‘ ’ to This update is acceptable.  Update the SSN of the EMPLOYEE tuple with SSN = ‘ ’ to ‘ ’. This update is unacceptable, because it violates primary key and referential integrity constraints.

Relational Algebra  Relational algebra is a set of operations to manipulate data and enable the user to specify basic retrieval requests.  The result of a retrieval is a new relation, which may have been formed from one or more relations.  Three groups of relational algebra operations:  Unary relational operations  Binary relational operations  Set theoretic operations

Relational Algebra  Unary relational operations:  The SELECT operation  The PROJECT operation