Relational Databases Relational Model Primary Keys Relation or Relationship Foreign Keys Relationships between entities Integrity Constraints Power of.

Slides:



Advertisements
Similar presentations
The Relational Database Model – some relations you might want to avoid!!!
Advertisements

The Relational Database Model
CIT 381 Slides part 3. Review: One-to-many and many-to-one One movie is stored on many videos – many videos are in one store. Both relationships are mandatory.
CIT 381 More ER Modeling - review one-to-many - one-to-one - recursive relationships.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
Information Resources Management February 13, 2001.
CIT 381 introduction to relations. Tables movieIdtitlegenrelengthrating 101The Thirty- Nine Steps mystery101R 123Annie Hallromantic comedy 110R 145Lady.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Database Design Chapter 3.
The Relational Database Model. 2 Objectives How relational database model takes a logical view of data Understand how the relational model’s basic components.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Final Project Preliminary Designs Pretty good designs. Remember that design is an iterative process. Don’t get married to your design. OK to change. You.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Why Normalization? To Reduce Redundancy to 1.avoid modification, insertion, deletion anomolies 2.save space Goal: One Fact in One Place.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Database Architecture The Relational Database Model.
IST Databases and DBMSs Todd S. Bacastow January 2005.
The Relational Database Model
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
© Pearson Education Limited, Chapter 2 The Relational Model Transparencies.
Relational Model Session 6 Course Name: Database System Year : 2012.
Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules.
DATA MODELING AND DATABASE DESIGN
RAJIKA TANDON DATABASES CSE 781 – Database Management Systems Instructor: Dr. A. Goel.
Relational DB Components
MIS 301 Information Systems in Organizations Dave Salisbury ( )
RELATIONSHIPS Generally there are two main database types: flat-file and relational.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
SQL, Data Storage Technologies, and Web-Data Integration Week 2.
Copyright © Curt Hill The Relational Model of Database Basic organization and terms.
The Relational Database Model
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
Databases. Not All Tables Are Created Equal Spreadsheets use tables to store data and formulas associated with that data The “meaning” of data is implicit.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
Relational Database. Database Management System (DBMS)
Copyright © 2003 Addison-Wesley Sree Nilakanta. Copyright © 2003 Addison-Wesley Developing Relational Models What is the relational model and what is.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
INFORMATION TECHNOLOGY DATABASE MANAGEMENT. Adding a new field 1Right click the table name and select design view 2Type the field information at the end.
In this session, you will learn to: Map an ER diagram to a table Objectives.
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.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Relational Theory and Design
Databases Illuminated Chapter 3 The Entity Relationship Model.
File and Database Design Class 22. File and database design: 1. Choosing the storage format for each attribute from the logical data model. 2. Grouping.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 3 The Relational Database Model.
Database Systems: Design, Implementation, and Management Ninth Edition Chapter 3 The Relational Database Model.
12/2/2015CPSC , CPSC , Lecture 41 Relational Model.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
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 DATABASE TECHNOLOGIES (Part 2) BUS Abdou Illia, Fall 2015 (September 9, 2015)
Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin APPENDIX C DESIGNING DATABASES APPENDIX C DESIGNING DATABASES.
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
3 1 Database Systems The Relational Database Model.
Logical Database Design and the Relational Model.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
SE305 Database System Technology 25/09/2014 Quiz-1.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Chapter 3 The Relational Database Model. Database Systems, 10th Edition 2 * Relational model * View data logically rather than physically * Table * Structural.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
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.
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.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Understanding Data Storage
CIS 207 The Relational Database Model
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Presentation transcript:

Relational Databases Relational Model Primary Keys Relation or Relationship Foreign Keys Relationships between entities Integrity Constraints Power of Relational Model More on relational keys

The relational model represents information in relations (called tables) –Each relation represents an entity (class) - table –Each column of a table represents the attributes of the entity - field –Each row of a table represents an instance of the entity – tuple or record –Each row/column intersection represents a single data value A database schema is a collection of table definitions (relation schemas) A relational database is a collection of tables –Each table stores objects for a single relation schema

The rows of a relational table are unique –No 2 rows have the same values for all of the attributes A primary key is an attribute or collection of attributes which uniquely identifies each row –No 2 rows have the same values for all attributes in the primary key Every table must have a primary key - Why? A primary key declaration is a constraint –A table is not allowed to have 2 different rows that have the same value for the primary key –Database systems enforce primary key constraints By blocking any attempt to modify a table that will result in a violation of the key constraint

Relation is not Relationship Be careful of these two words –Relation –Relationship A relation is a table that contains rows (instances of entity) A relationship is a connection between two entities Why is the relational model so named? –Not because of the relationships between entities –Because it is a collection of relations

Foreign Keys Controlled redundancy is how the relational model works. Relations share a common attribute and are thus linked. When an attribute of a relation is also the primary key of another relation that attribute is called a foreign key. Consider our video/movie problem again. Looking at an instance of a video (which is now a relation) we can use the MOVIE_ID to locate the info about the movie in the movie relation. Yes, the MOVIE_ID is redundant data, but it is controlled redundancy and this is the power of the relational model.

Movie movieIdtitlegenrelengthrating 101The Thirty-Nine Steps mystery101R 123Annie Hallromantic comedy 110R 145Lady and the Tramp animated comedy 93PG 189Animal Housecomedy87PG Elizabethcostume drama123PG Stagecoachwestern130R 987Duck Soupcomedy99PG-13

Video videoIddateAcquiredmovieIdstoreId 1011/25/ /5/ /31/ /5/ /5/ /25/ /12/ /29/ /25/ /10/

Relationships between entities The relational model can only handle two types of relationships between entities: –One-to-one (OK) Sale and item??? –One-to-many (most useful in the relational model) A movie is copied on many videos (DVDs if not in Oakridge) –Many-to-many (can’t do this in the relational model) We have to create a new entity or relation called a bridge entity or bridge or junction table

One-to-one Relationship Consider the relationship between video and CurrentRental again Each Video can only be currently rented once and each CurrentRental can only involve a single video. Both have the same primary key (videoId). Usually when you have a one-to-one relationship you should seriously consider whether there should only be one entity instead of two.

One-to-many Relationship Consider the relationship between movie and video We link these relations by taking the primary key of the one and putting it into the many relation. It is considered a foreign key in the second relation. If the relationship is identifying then the foreign key will be part of the primary key If the relationship is non-identifying then the foreign key will not be part of the primary key

Many-to-Many Relationship Types Many-to-Many relationships between 2 entities cannot be represented as simple attributes in either related table Consider the relationship between truck drivers and trucks at a trucking company. Each driver drives many trucks and each truck is driven by many drivers. How do we represent that in the relational model? We create a new bridge entity or table. Perhaps we call it a trip. We take the primary keys from each of the entities and they become the primary key for the new entity. (draw driver and truck)

Integrity constraints The relational model provides two types of integrity constraints to ensure the integrity of the data: Entity integrity – the primary key column of a table cannot contain any null values and each value must be unique Referential integrity – the foreign key column of a relation must contain either nulls or if a value is not null the value must exist as a primary key in the related table. The RDBMS enforces these constraints for us

Power of Relational Model Abstraction –The table is a logical structure –Much easier to understand and work with –No physical structures Manipulation/Extraction –Relational Algebra –SQL standard (sort of) with all RDBMS

More on relational keys Superkey An attribute (or combination of attributes) that uniquely identifies each instance in a table Candidate key A minimal superkey. A superkey that does not contain a subset of attributes that is itself a superkey Primary key A candidate key selected to uniquely identify all other attribute values in any given row. Cannot contain null entries. Alternate key A candidate key that is not the primary key (might be used as secondary access via an index) Foreign key An attribute or combination of attributes of a table that are also the primary key of another table. Composite key A key that is composed of more than one attribute.