FEN 2014-02-061  Concepts and terminology  Operations (relational algebra)  Integrity constraints The relational model.

Slides:



Advertisements
Similar presentations
The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
Advertisements

Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Foundations of Relational Implementation n Defining Relational Data n Relational Data Manipulation n Relational Algebra.
Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
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.
The Relational Model Codd (1970): based on set theory Relational model: represents the database as a collection of relations (a table of values --> file)
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Database Architecture The Relational Database Model.
3 The Relational Model MIS 304 Winter Class Objectives That the relational database model takes a logical view of data That the relational model’s.
Databases Illuminated
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
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.
© Pearson Education Limited, Chapter 2 The Relational Model Transparencies.
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.
Chapter 4 The Relational Model.
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
Database Technical Session By: Prof. Adarsh Patel.
CG084&085 / / 1 The Relational Data Model Properties of Relations Keys and Constraints.
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.
The Relational Data Model and Relational Database Constraints
10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Module 3: The Relational Model.  Overview Terminology Relational Data Structure Mathematical Relations Database Relations Relational Keys Relational.
Chapter 3 The Relational Model. 2 Chapter 3 - Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between.
1 CSE 480: Database Systems Lecture 5: Relational Data Model.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Ihr Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
10/17/2012ISC471/HCI571 Isabelle Bichindaritz 1 Technologies Databases.
Chapter 6 The Relational Data Model and the Relational Algebra.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
Structured Query Language Chris Nelson CS 157B Spring 2008.
FEN  Data Definition: CREATE TABLE, ALTER TABLE  Data Manipulation: INSERT, UPDATE, DELETE  Queries: SELECT SQL: Structured Query Language.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
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.
FEN Introduction to the database field:  Applications, concepts and terminology Seminar: Introduction to relational databases.
Relational Database. Database Management System (DBMS)
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
FEN Introduction to the database field:  The Relational Model Seminar: Introduction to relational databases.
CSc340 1b1 The Relational Model Chapter 2 Database Schema Keys Schema Diagrams Relational Query Languages Relational Operations.
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Concepts 2440: 180 Database Concepts Instructor:
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Computing & Information Sciences Kansas State University Friday, 26 Jan 2008CIS 560: Database System Concepts Lecture 2 of 42 Friday, 29 August 2008 William.
Chapter 2 Introduction to Relational Model. Example of a Relation attributes (or columns) tuples (or rows) Introduction to Relational Model 2.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
 CS 405G: Introduction to Database Systems Lecture 6: Relational Algebra Instructor: Chen Qian.
Relational Data Model DeSiaMore Powered by DeSiaMore.
The Relational Model. 2 Relational Model Terminology u A relation is a table with columns and rows. –Only applies to logical structure of the database,
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Databases Introduction - concepts. Concepts of Relational Databases.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Lecture 2 The Relational Model
Chapter 2: Intro to Relational Model
The Relational Model Textbook /7/2018.
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Presentation transcript:

FEN  Concepts and terminology  Operations (relational algebra)  Integrity constraints The relational model

Relational Databases All data is organised in tables with atomic values Associations are represented by primary key/foreign key connections Every operation operates on tables and returns tables FEN Small exercise (5 min..): Describe step by step how you will retrieve this information: When did Mr Smith attend the “Intro to Computer Science” course, who was the instructor and what grade did he receive?

The Relational Model A sound theoretical data model (Codd, 1970). Based on the mathematical theory of relations, sets and first order predicate logic. De facto standard since the late eighties. Many-many implementations – most SQL-based. FEN The Notorious Supplier-Part Database (Date) For instance: Oracle MySQL MS SQL Server PostgreSQL For instance: Oracle MySQL MS SQL Server PostgreSQL

The Relational Model: Concepts FEN Central concepts: Tables (relations). Columns (attributes). Type (domain). Rows (tuples). Tuples are unordered. Tuples are unique. A relation is a set (mathematical) of tuples. Primary and foreign keys The Notorious Supplier-Part Database (Date)

The Relational Model Data is organised in a number of tables (relations). Each table has a number (>=1) columns (attributes). Attributes are atomic and defined over some domain. A table holds a number (maybe none) rows (tuples). Tuples are unordered. Tuples are unique (existence of a key is guaranteed). A relation is a set (mathematical) of tuples. FEN

Attributes and Domains A domain defines the valid value of an attribute. Domains are based on the built-in standard data types (int, char etc.) offered by the DBMS. Theoretically it should be possible to define problem specific domains as CPR numbers, account numbers, IP addresses etc. and complex aggregate (structured) domain as maps, diagrams, pictures, sound bites, video clips etc. More attributes may be defined over the same domain. An attribute may have the value “empty” (not known /not defined for this instance). Empty is notated NULL. FEN

Properties of a Relation Follows from the fact that relations are (mathematically) sets: Tuples must be unique within a relation (hence a primary key always exists) Tuples are unordered (vertically) Attributes are unordered (horizontally) Attribute values are atomic Note the difference to the usual notion of a table FEN

Keys A key is a combination of attributes that is: Unique and Minimal An attribute combination that is unique, but not minimal is called a superkey The set of all attributes will always be a superkey, hence a superkey (and a key) always exists. A relation (table) may have several candidate keys. One these is appointed primary key. FEN Any primary keys here?

Associations Between Relations Associations are represented by foreign keys. A foreign key is an attribute (combination) that corresponds to an attribute (combination) of the primary key of some other relation. A foreign key references a tuple in another relation and indicates that here is more information about the entity. Foreign key attributes and corresponding primary key attributes must be defined over compatible domains (normallly the same domain). FEN Any foreign keys here?

Integrity Constraints FEN Domain constraints Attributes may only hold valid values Entity Integrity Primary key attributes may not hold NULL-values Referential Integrity (foreign key constraint) A foreign key must either be NULL or reference an existing primary key in the other relation Semantic Integrity Constraints depending on the problem domain Any constraints here?

Example: MiniBank Two tables: Customers Accounts Associated: An account belongs to one customer FEN Association Any constraints here? (primary keys – foreign keys) Any constraints here? (primary keys – foreign keys)

Example: MiniBank What happens if: We try to insert a customer with an existing custNo? We try to insert an account with a not existing custNo? Let’s try in MS SQL Server FEN

Example: MiniBank Table definitions (schemas): FEN Constraint

Quering a relational database Database Languages: Data Definition DDL Should provide constructs for defining all the previous (as “create table) Data Manipulation DML (queries, insert, delete, update) procedural (How?) nonprocedural (What?) The Relational Algebra is a procedural DML SQL includes a (sort of) nonprocedural DML FEN

The Relational Algebra Data Manipulation in the Relational Model Operates on relations, which are input to the operations is tables and the result is a table Operations Row selection (RESTRICT/SELECT) Column selection (PROJECT) Combining tables (JOIN) Set operations (UNION, INTERSECTION, DIFFERENCE, PRODUCT) More advanced operations (OUTER (LEFT/RIGTH) JOIN) FEN

Relational Algebra - Overview FEN

Example: MiniBank Retrieve information about customer number 3: Row selection on custNo = 3 from Customer Retrieve account number, balance and customer number for accounts with a balance between 1000 and 2000: Row selection on 1000 <= balance and balance <= 2000 from Account Column selection on accNo, balance, custNo Retrieve information about customer Tommy and his accounts: Row selection on name = ‘Tommy’ from Customer Join with Account on custNo FEN What if we have more than one customer called ‘Tommy’? And what if we have no ‘Tommy’? What if we have more than one customer called ‘Tommy’? And what if we have no ‘Tommy’?

18 Informal TermsFormal Terms TableRelation ColumnAttribute/Domain RowTuple Values in a columnDomain Table DefinitionSchema of a Relation Definitions - Summary FEN

19 Another example: Company: FEN

20 Company: Sample data FEN

21 Company: Sample data – cont… FEN

22 Company: Exercise FEN Do exercise 1 on CompanyExercise.pdf CompanyExercise.pdf (Exercise 2, phase 1 and 2)