Keys  SuperKey  a set of attributes whose values together uniquely identify a tuple in a relation  Candidate Key  a superkey for which no proper subset.

Slides:



Advertisements
Similar presentations
Normalisation. Informal guidelines  Semantics of the attributes  easy to explain relation  doesn’t mix concepts  Reducing the redundant values in.
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.
Keys  SuperKey  a set of attributes whose values together uniquely identify a tuple in a relation  Candidate Key  a superkey for which no proper subset.
1 Assignment 4 Map entities with relationships to relational schemas. Use DBDL to describe the table schemas.
Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
Relational Model Stores data as tables –Each column contains values about the same attribute –Each column has a distinct name –Each row contains values.
Relational Model and Relational Algebra Rose-Hulman Institute of Technology Curt Clifton.
1 Minggu 2, Pertemuan 3 The Relational Model Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
1 Pertemuan 04 MODEL RELASIONAL Matakuliah: >/ > Tahun: > Versi: >
July 14, 2015ICS 424: recap1 Relational Database Design: Recap of ICS 324.
Thomas Connolly and Carolyn Begg’s
Database Systems Relational Model Concepts Toqir Ahmad Rana Database Management Systems 1 Lecture 17.
Database Architecture The Relational Database Model.
Data Definition, Relational Manipulation and Data Control Using SQL.
CSC271 Database Systems Lecture # 6. Summary: Previous Lecture  Relational model terminology  Mathematical relations  Database relations  Properties.
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.
Chapter 4 The Relational Model.
Relational Data Model. A Brief History of Data Models  1950s file systems, punched cards  1960s hierarchical  IMS  1970s network  CODASYL, IDMS 
RAJIKA TANDON DATABASES CSE 781 – Database Management Systems Instructor: Dr. A. Goel.
Relational Query Languages. Languages of DBMS  Data Definition Language DDL  define the schema and storage stored in a Data Dictionary  Data Manipulation.
Introduction to Database Systems Mapping ER Models to Relational Schemas Irvanizam Zamanhuri, M.Sc Informatics (Computer Science) Study Program Syiah Kuala.
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.
R ELATIONAL D ATA M ODEL Joe Meehean 1. R ELATIONAL D ATA M ODEL Data stored as a set of relations really just tables Tables related to one another through.
CS530 Database Architecture Models and Design Prof. Ian HORROCKS Dr. Robert Stevens Wednesday - Practical Tables.
Database Systems Lecture # 7 8 th Feb, Conceptual and Logical Design Person buys Product name pricenamessn Conceptual Model: Relational Model: (plus.
(Extended) Entity Relationship Modelling and Mappings to the Relational Data Model.
1 CS 3630 Database Design and Implementation. 2 Sets Foundation of relational database. Basic Operations Power set Mapping.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
The Relational Model Pertemuan 03 Matakuliah: M0564 /Pengantar Sistem Basis Data Tahun : 2008.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Database Systems, 9th Edition 1.  In this chapter, students will learn: That the relational database model offers a logical view of data About the relational.
Announcements Reading for Monday –4.6 Homework 3 – Due 9/29.
1 Web Database The Relational Data Model Irvanizam Zamanhuri, M.Sc Computer Science Study Program Syiah Kuala University Website :
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
12/2/2015CPSC , CPSC , Lecture 41 Relational Model.
L8-2-S1 Misc Topics © M.E. Fayad SJSU -- CmpE Database Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of.
Instructor: Jinze Liu Fall Phases of Database Design u Conceptual design begins with the collection of requirements and results needed from the.
Normalization MIS335 Database Systems. Why Normalization? Optimizing database structure Removing duplications Accelerating the instructions Data integrity!
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,
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Lecture 03 Constraints. Example Schema CONSTRAINTS.
Howard Paul. Sequential Access Index Files and Data File Random Access.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
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.
CSCI 6315 Applied Database Systems Review for Midterm Exam I Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Week 2 Lecture The Relational Database Model Samuel ConnSamuel Conn, Faculty Suggestions for using the Lecture Slides.
Chapter 4 The Relational Model Pearson Education © 2009.
Database Designsemester Slide 1 Database Design Lecture 7 Entity-relationship modeling Text , 7.1.
Simplified phases of Database Design
Chapter 2: Relational Model
The Relational Data Model and Relational Database Constraints
Lecture # 13 (After 1st Exam)
Chapter 4 The Relational Model Pearson Education © 2009.
02 - The Relational Database Model
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Practical Relevance Examples Class Laboratory
Chapter 4 The Relational Model Pearson Education © 2009.
Presentation transcript:

Keys  SuperKey  a set of attributes whose values together uniquely identify a tuple in a relation  Candidate Key  a superkey for which no proper subset is a superkey…a key that is minimal.  Can be more than one for a relation  Primary Key  a candidate key chosen to be the main key for the relation.  One for each relation  Keys can be composite

e.g.: Staff(lecturer,roomno,appraiser) SK = {lecturer,roomno,appraiser}, {lecturer,roomno}, {lecturer, appraiser}, {roomno,appraiser}, {lecturer} and {roomno} CK = {lecturer} and {roomno} PK = {lecturer}

Foreign Key  a (set of) attribute(s) in a relation that exactly matches a (primary) key in another relation  the names of the attributes don’t have to be the same but must be of the same domain  a foreign key in a relation A matching a primary key in a relation B represents a  many:one relationship between A and B Student(studno,name,tutor,year) Staff(lecturer,roomno,appraiser)

Relationship -v- Relation SCHOOL REG m 1 name STUDENT studno faculty hons STUDENT (studno, name, hons) SCHOOL(hons, faculty) Relationship Relation (table) “an association between several entities represented by a Relationship Type of which there will be many Relationship Instances”

Relationship -v- Relation COURSE exammark ENROL m n name STUDENT studno subject courseno STUDENT (studno, name) ENROL(studno, courseno,exammark) COURSE(courseno, subject) ENROL Relation ENROL Relationship

STUDENT studnonametutor s1jonesbush s2brownkahn s3smithgoble STAFF lecturerroomno kahnIT206 bush2.26 Joins e.g., get studno, name and tutor’s roomno for each student

STUDENT studnonametutor s1jonesbush s2brownkahn s3smithgoble STAFF lecturerroomno kahnIT206 bush2.26

STUDENT studnonametutor s1jonesbush s2brownkahn s3smithgoble STAFF lecturerroomno kahnIT206 bush2.26 studnonametutor s1jonesbush s2brownkahn s3smithbush lecturerroomno kahnIT206 bush2.26 s1jonesbush s2brownkahn IT206 bush2.26 kahnIT206 bush2.26 s3smithbush SELECT FROM STUDENT a, STAFF b WHERE  studno,name,roomno (STUDENT tutor=lecturer STAFF)

STUDENT studnonametutor s1jonesbush s2brownkahn s3smithgoble STAFF lecturerroomno kahnIT206 bush2.26 studnonametutor s1jonesbush s2brownkahn s3smithbush lecturerroomno kahnIT206 bush2.26 s1jonesbush s2brownkahn IT206 bush2.26 kahnIT206 bush2.26 s3smithbush SELECT FROM STUDENT a, STAFF b WHERE a.tutor=b.lecturer  studno,name,roomno (STUDENT tutor=lecturer STAFF)

STUDENT studnonametutor s1jonesbush s2brownkahn s3smithgoble STAFF lecturerroomno kahnIT206 bush2.26 studnonametutor s1jonesbush s2brownkahn s3smithbush lecturerroomno kahnIT206 bush2.26 s1jonesbush s2brownkahn IT206 bush2.26 kahnIT206 bush2.26 s3smithbush SELECT a.studno, a.name, b.roomno FROM STUDENT a, STAFF b WHERE a.tutor=b.lecturer  studno,name,roomno (STUDENT tutor=lecturer STAFF)

STUDENT studnonametutor s1jonesbush s2brownkahn s3smithgoble STAFF lecturerroomno kahnIT206 bush2.26 studnonametutor s1jonesbush s2brownkahn s3smithbush lecturerroomno kahnIT206 bush2.26 s1jonesbush s2brownkahn IT206 bush2.26 kahnIT206 bush2.26 s3smithbush SELECT a.studno, a.name, b.roomno FROM STUDENT a, STAFF b WHERE a.tutor=b.lecturer and studno=‘s1’  studno=‘s1’ (  studno,name,roomno (STUDENT tutor=lecturer STAFF) )

Join as Path HOTEL (hotelid, name, resort) RESORT(resort, region) REGION(region,country) Get hotels and their regions Residences m Hotel hotelid Resort resort RegLoc m Region region 11 SELECT FROM WHERE

HOTEL (hotelid, name, resort) RESORT(resort, region) REGION(region,country) Get hotels and their regions Residences m Hotel hotelid Resort resort RegLoc m Region region 11 SELECT FROM HOTEL, RESORT, REGION WHERE

HOTEL (hotelid, name, resort) RESORT(resort, region) REGION(region,country) Get hotels and their regions Residences m Hotel hotelid Resort resort RegLoc m Region region 11 SELECT FROM HOTEL, RESORT, REGION WHERE hotel.resort=resort.resort

HOTEL (hotelid, name, resort) RESORT(resort, region) REGION(region,country) Get hotels and their regions Residences m Hotel hotelid Resort resort RegLoc m Region region 11 SELECT FROM HOTEL, RESORT, REGION WHERE hotel.resort=resort.resort and resort.region=region.region hotel.resort=resort.resort resort.region=region.region

HOTEL (hotelid, name, resort) RESORT(resort, region) REGION(region,country) Get hotels and their regions Residences m Hotel hotelid Resort resort RegLoc m Region region 11 SELECT hotel.name, region.region FROM HOTEL, RESORT, REGION WHERE hotel.resort=resort.resort and resort.region=region.region hotel.resort=resort.resort resort.region=region.region

More SQL Cinema (cid, name, city) Film (fid, title, director) Showing (fid, cid) Name, city and the number of different films showing at each cinema, in ascending alphabetical order of city and name

select name, city, count(*) as films

select name, city, count(*) as films from Film f, Cinema c, Showing s

select name, city, count(*) as films from Film f, Cinema c, Showing s where f.fid=s.fid and c.cid=s.cid

select name, city, count(*) as films from Film f, Cinema c, Showing s where f.fid=s.fid and c.cid=s.cid group by c.cid

select name, city, count(*) as films from Film f, Cinema c, Showing s where f.fid=s.fid and c.cid=s.cid group by c.cid order by city, name;

Cinema (cid, name, city) Film (fid, title, director) Showing (fid, cid) Titles of films showing at every cinema listed in database.

(select * from showing s where s.cid=c.cid and f.fid=s.fid)

(select * from cinema c where not exists (select * from showing s where s.cid=c.cid and f.fid=s.fid))

select title from film f where not exists (select * from cinema c where not exists (select * from showing s where s.cid=c.cid and f.fid=s.fid));