CS 405G: Introduction to Database Systems Lecture 4: Relational Model Instructor: Chen Qian.

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)
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
The Relational Model CS 186, Fall 2006, Lecture 2 R & G, Chap. 3.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
Chapter 3: Relational Model
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
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.
Chapter 5 Relational Model Concepts Dr. Bernard Chen Ph.D. University of Central Arkansas.
The Relational Model These slides are based on the slides of your text book.
Data Models Amandeep Kaur Lecturer GPC Khunimajra Call at
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.
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
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.
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 Chapter 5 The Relational Data Model and Relational Database Constraints.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
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.
ICOM 5016 – Introduction to Database Systems Lecture 5b Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Chapter 6 The Relational Data Model and the Relational Algebra.
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.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
The Relational Model Content based on Chapter 3 Database Management Systems, (Third Edition), by Raghu Ramakrishnan and Johannes Gehrke. McGraw Hill, 2003.
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.
CS 405G: Introduction to Database Systems Lecture 5: Logical Design by Relational Model Instructor: Chen Qian.
Instructor: Jinze Liu Fall Phases of Database Design u Conceptual design begins with the collection of requirements and results needed from the.
Relational Data Model DeSiaMore Powered by DeSiaMore.
Chapter 5 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
The Relational Data Model and Relational Database Constraints
Chapter 3 The Relational Model. Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1.
The Relational Data Model and Relational Database Constraints.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
4/28/2017 Chapter 5 The Relational Data Model and Relational Database Constraints.
Copyright © 2004 Pearson Education, Inc.
4/20/2018.
The Relational Data Model
The Relational Data Model and Relational Database Constraints
The Relational Model Relational Data Model
12/7/2018.
The Relational Data Model and Relational Database Constraints
4/8/2019.
EECS 647: Introduction to Database Systems
CS 505: Intermediate Topics to Database Systems
5/12/2019.
Copyright © 2004 Pearson Education, Inc.
CS 405G: Introduction to Database Systems
Presentation transcript:

CS 405G: Introduction to Database Systems Lecture 4: Relational Model Instructor: Chen Qian

7/2/20152 Review A data model is a group of concepts for describing data. What are the two terms used by ER model to describe a miniworld? Entity Relationship What makes a good conceptual database design ? 27/2/2015

3 Today’s Outline Relational Model Relational Model and Relational Database Schemas Informal definition, not so formal, and formal Relational Model Constraints

7/2/20154 Why Study the Relational Model? Most widely used model. “Legacy systems” in older models e.g., IBM’s IMS Object-oriented concepts merged in “Object-Relational” model Early work done in POSTGRES research project at Berkeley XML features in most relational systems Can export XML interfaces Can embed XML inside relational fields

7/2/20155 Historically The model was first proposed by Dr. E.F. Codd of IBM in 1970 in the following paper: "A Relational Model for Large Shared Data Banks," Communications of the ACM, June The above paper caused a major revolution in the field of Database management and earned Ted Codd the coveted ACM Turing Award. The picture is from wikipedia

7/2/20156 Database Design

7/2/20157 Relational Model Concepts Relational database: a set of relations. Relation: made up of 2 parts: Schema : specifies name of relation, plus the name and type of each attribute. E.g. Students(sid: string, name: string, login: string, age: integer, gpa: real) Instance : a table, with rows and columns. #rows = cardinality #fields = degree / arity

7/2/20158 Relation RELATION: A table of values A relation may be thought of as a set of rows (table view). Each row represents a fact that corresponds to a real- world entity or relationship. Each row has a value of an item or set of items that uniquely identifies that row in the table.

7/2/20159 Relation Sometimes row-ids or sequential numbers are assigned to identify the rows in the table. A relation may alternately be thought of as a set of columns (schema view). Each column typically is called by its column name or column header or attribute name.

7/2/ A (Slightly) Formal Definition A database is a collection of relations (or tables) Each relation is identified by a name and a list of attributes (or columns) Each attribute has a name and a domain (or type) Such as SID:string Set-valued attributes not allowed Simplicity is a virtue!

Schemas 11 Relation schema = relation name + attributes + types of attributes in order Example: Beers(name, manf) or Beers(name: string, manf: string) Database = collection of relations. Database schema = set of all relation schemas in the database.

7/2/ Schema versus instance Schema (metadata) Students(sid: string, name: string, login: string, age: integer, gpa: real) Specification of how data is to be structured logically Defined at set-up; Rarely changes Instance Content Changes rapidly, but always conforms to the schema  Compare to type and objects of type in a programming language  Entity and entity type?

7/2/ Example Schema Student (SID integer, name string, age integer, GPA float) Course (CID string, title string) Enroll (SID integer, CID integer) Instance { 142, Amy, 20, 3.3, 123, Bob, 22, 3.1,...} { CS405G, Intro. to Database Systems,...} { 142, CS405G, 142, CS314,...}

7/2/ Formal Definition (Set Theory) Formally, given sets D 1, D 2, …. D n a relation r is a subset of D 1 x D 2 x … x D n x: Cartesian product For sets A and B, the Cartesian product A × B is the set of all ordered pairs (a, b) where a ∈ A and b ∈ B. Thus, a relation is a set of n-tuples (a 1, a 2, …, a n ) where each a i  D i

7/2/ Example Example: If customer_name = {Jones, Smith, Curry, Lindsay, …} customer_street = {Main, North, Park, …} customer_city = {Harrison, Rye, Pittsfield, …} Then r = { (Jones, Main, Harrison), (Smith, North, Rye), (Curry, North, Rye), (Lindsay, Park, Pittsfield) } is a relation over customer_name × customer_street × customer_city

7/2/ Attribute Types Each attribute of a relation has a name, designating the role of the attribute The set of allowed values for each attribute is called the domain of the attribute Attribute values (domain members) are required to be atomic; that is, indivisible E.g. the value of an attribute can be an account number, but cannot be a set of account numbers Domain is said to be atomic if all its members are atomic The special value null is a member of every domain

7/2/ Relation Schema A 1, A 2, …, A n are attributes R = (A 1, A 2, …, A n ) is a relation schema Example: Customer_schema = (customer_name, customer_street, customer_city) r(R) denotes a relation r on the relation schema R Example: customer (Customer_schema)

7/2/ Relation Instance The current values (relation instance) of a relation are specified by a table An element t of r is a tuple, represented by a row in a table Jones Smith Curry Lindsay customer_name Main North Park customer_street Harrison Rye Pittsfield customer_city customer attributes (or columns) tuples (or rows)

7/2/ Definition Summary Informal TermsFormal Terms TableRelation ColumnAttribute/Domain RowTuple Values in a columnDomain Table DefinitionSchema of a Relation Populated TableExtension

7/2/ Characteristics of Relation The tuples in a ration r(R) are not considered to be ordered, even though they appear to be in the tabular form. We consider the attributes in R(A 1, A 2,..., A n ) and the values in t= to be ordered. All values are considered atomic (indivisible). A special null value is used to represent values that are unknown or inapplicable to certain tuples.

7/2/ Characteristics of Relation Notation: 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.

7/2/ Relational Integrity Constraints Integrity Constraints are conditions that must hold on all valid relation instances. There are four main types of constraints: 1. Domain constraints 1. The value of a attribute must come from its domain 2. Key constraints 3. Entity integrity constraints 4. Referential integrity constraints

Primary Key Constraints A set of fields is a candidate key (abbreviated as key) for a relation if : 1. No two distinct tuples can have same values in all key fields, and 2. Property 1 is not true for any subset of the key. What if Part 2 is false? A super key: a set of fields that contains a key. If there are multiple keys for a relation, one of the keys is chosen (by DBA) to be the primary key.

7/2/ Key Example E.g., given a schema Student(sid: string, name: string, gpa: float) we have: sid is a key for Students. (What about name?) The set {sid, gpa} is a superkey. CAR (licence_num: string, Engine_serial_num: string, make: string, model: string, year: integer) What is the candidate key(s) Which one you may use as a primary key What are the super keys

7/2/ Entity Integrity Entity Integrity: The primary key attributes (PK) of each relation schema R cannot have null values in any tuple of r(R). Other attributes of R may be similarly constrained to disallow null values, even though they are not members of the primary key.

Foreign Keys, Referential Integrity Foreign key : Set of fields in one relation that is used to `refer’ to a tuple in another relation. (Must correspond to primary key of the second relation.) Like a `logical pointer’. Foreign key constraint: The foreign key in the referencing relation must match the primary key of the referenced relation. E.g. sid is a foreign key referring to Students : Student(sid: string, name: string, gpa: float) Enrolled(sid: string, cid: string, grade: string) If all foreign key constraints are enforced, referential integrity is achieved, i.e., no dangling references.

Foreign Key constraints Only students listed in the Students relation should be allowed to enroll for courses. Enrolled Students Possible violation: Add to Enrolled. Possible violation: delete from Students.

7/2/ Other Types of Constraints Semantic Integrity Constraints: based on application semantics and cannot be expressed by the model per se e.g., “the max. no. of hours per employee for all projects he or she works on is 56 hrs per week” A constraint specification language may have to be used to express these SQL-99 allows triggers and ASSERTIONS to allow for some of these

Next class Logical design of databases using the relational model. 7/2/201529

Home work 1, due 2/6 7/2/201530