Movies length titleyearfilmType Voices isa Cartoons isa MurderMystery weapon toStar Our Movie Example.

Slides:



Advertisements
Similar presentations
High-Level Database Models Spring 2011 Instructor: Hassan Khosravi.
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.
Tallahassee, Florida, 2014 COP4710 Database Systems Relational Model Fall 2014.
Database Modifications CIS 4301 Lecture Notes Lecture /30/2006.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
1 Introduction to Database Systems CSE 444 Lectures 19: Data Storage and Indexes November 14, 2007.
Functional Dependencies - Example
1 Convert E/R to Relation May 18, Entity Set -> Relation Relation: Beers(name, manf) Beers name manf.
Database Principles ER to RDM Mapping. Database Principles Mapping from ER to Relational Data Model the next phase Exercise: Give me some suggestions.
Database Modifications, Data Types, Views. Database Modifications A modification command does not return a result as a query does, but it changes the.
Design Principles: Faithfulness
Database Modifications, Data Types, Views. Database Modifications A modification command does not return a result as a query does, but it changes the.
Indexes. An index on an attribute A of a relation is a data structure that makes it efficient to find those tuples that have a fixed value for attribute.
Design Principles: Faithfulness
Sanjay Goel, School of Business, University at Albany, SUNY 1 SQL- Data Definition Language ITM 692 Sanjay Goel.
Relational Model CS 157A Prof. Sin-Min Lee By Truc Truong.
Fall 2001Arthur Keller – CS 1808–1 Schedule Today Oct. 18 (TH) Schemas, Views. u Read Sections u Project Part 3 extended to Oct. 23 (T). Oct.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
Additional ODL Concepts OO Model to Relational Model Object-Relational Design OO vs OR.
A four-way Relationship
Data Modelling. EAR model This modelling language allows a very small vocabulary: Just as English has nouns, verbs, adjectives, pronouns.., EAR models.
Database Modifications A modification command does not return a result as a query does, but it changes the database in some way. There are three kinds.
From E/R Diagrams to Relations. The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes.
1 The Entity-Relationship Data Model Chapter 2 (Database Design)
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
1 Relational Data Model CS 157B Nidhi Patel. 2 What is a Data Model? A notation for describing data or information A notation for describing data or information.
Database Design & ER Diagrams
Using ER/Studio.
Database Systems Lecture 5 Natasha Alechina
ER- and EER-to-Relational Mapping
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
1 The Relational Model Instructor: Mohamed Eltabakh
Conversion E/R to Relational CIS 4301 Lecture Notes Lecture 6 - 1/31/2006.
Introduction to Indexes. Indexes An index on an attribute A of a relation is a data structure that makes it efficient to find those tuples that have a.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Entity-Relationship (ER) Modelling ER modelling - Identify entities - Identify relationships - Construct ER diagram - Collect attributes for entities &
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
© D. Wong Ch. 2 Entity-Relationship Data Model (continue)  Data models  Entity-Relationship diagrams  Design Principles  Modeling of constraints.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Referential Integrity checks, Triggers and Assertions Examples from Chapter 7 of Database Systems: the Complete Book Garcia-Molina, Ullman, & Widom.
© D. Wong Normalization  Purpose: process to eliminate redundancy in relations due to functional or multi-valued dependencies.  Decompose relation.
1 CSCE Database Systems Anxiao (Andrew) Jiang The Database Language SQL.
The Entity-Relationship Model CIS 4301 Lecture Notes 1/12/2006.
SQL Exercises – Part I April
Databases : SQL-Schema Definition and View 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 5 Introduction to a First Course in Database Systems.
The Relational Model of Data Prof. Yin-Fu Huang CSIE, NYUST Chapter 2.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 18 A First Course in Database Systems.
Functional Dependencies. Babies Exercise 2.2.5: At a birth, there is one baby (twins would be represented by two births), one mother, any number of nurses,
Databases : Functional Dependencies 2007, Fall Pusan National University Ki-Joune Li.
© D. Wong Ch. 3 (part 1)  Relational Model basics  From E/R diagram to Relations.
High-level Database Models Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
The Entity-Relationship Diagram for Data Modeling
1 Constraints and Triggers in SQL. 2 Constraints are conditions that must hold on all valid relation instances SQL2 provides a variety of techniques for.
ER Diagrams and Relational Model CS 174a (Winter 2015)
CPSC-310 Database Systems
Chap 3. High-Level Database Models
COP4710 Database Systems Relational Model.
Introduction to Structured Query Language (SQL)
Translation of ER-diagram into Relational Schema
CS4222 Principles of Database System
SQL OVERVIEW DEFINING A SCHEMA
Defining a Database Schema
Lecture 19: Data Storage and Indexes
Introduction to Database Systems CSE 444 Lectures 19: Data Storage and Indexes May 16, 2008.
SQL – Constraints & Triggers
CMSC-461 Database Management Systems
SQL (Structured Query Language)
Presentation transcript:

Movies length titleyearfilmType Voices isa Cartoons isa MurderMystery weapon toStar Our Movie Example

Subclass Structures to Relations There are two different approaches to organize relations that represent a hierarchy of classes regarding OO and E/R models. In OO –An object belongs to exactly one class. –An object inherits properties from all its super-classes but it is not a member of them. In E/R model –An “object” can be represented by entities belonging to several entity sets that are related by isa relationships. –Thus, the linked entities together represent the object and give that object its properties (attributes and relationships).

OO approach OO way: –Every subclass has its own relation. –All the properties of that subclass, including all its inherited properties, are represented in this relation. Example: For our example the relational database schema would be: –Movies( title, year, length, filmType ) –Cartoons( title, year, length, filmType ) –MurderMysteries( title, year, length, filmType, weapon) –Cartoon-MurderMysteries( title, year, length, filmType, weapon)

Can we merge Cartoons with Movies? –If we do, we lose information about which moves are cartoons. For the relationship Voices, we create: –Voices( title, year, starName ) Is it necessary to create two relations one connecting cartoons with stars, and one connecting cartoon-murder-mysteries with stars? –Not, really.

E/R way The entity set Movies will be represented by the relation: –Movies(title, year, length, filmType). The entity set MurderMystery will be represented by the relation: –MurderMystery(title, year, weapon). The entity set Cartoons will be represented by the relation: –Cartoons(title, year). This relation has no attribute other than the key for movies. The relationship Voices will be represented by the relation: –Voices(title, year, name). The last attribute is the key for Stars and the first two form the key for Cartoons.

E/R way (II) Remark: –There is no relation corresponding to the class Cartoon-MurderMystery. –For a movie that is both, we obtain: its voices from the Voices relation, its weapon from the MurderMystery relation, and all other information from the Movies relation. The relation Cartoons has a schema that is a subset of the schema for the relation Voices. Should we eliminate the relation Cartoons? However there may be silent cartoons in our database. Those cartoons would have no voices and we would lose them.

Comparison of Approaches OO translation drawback: Should we want to find an object, it forces us to search several relations. –For example, if we want to find “Robin Hood”, we should search four different relations, until we find the relation for the class the movie is in. E/R translation drawback: We may have to look in several relations to gather information about a single object. For example, if we want the length and weapon used for a murder mystery film, we have to look at all the relations.

OO translation advantage: The OO translation keeps all properties of an object together in one relation. E/R translation advantage: The E/R translation allows us to find in one relation tuples from all classes in the hierarchy. In simple words: –To find the value of a general (of all classes) attribute is easier in E/R translation. We just look at the relation of the super-class. –To find the value of a specific (not of all classes) attribute along with the value of a general one, is easier in the OO translation. In the E/R translation we have to join the relation of the super-class with the relation for the child. Comparison of Approaches (Continued)

What movies of 1999 were longer than 150 minutes? –Can be answered directly in the E/R approach. –In the OO approach we have to examine all the relations. What weapons were used in cartoons of over 150 minutes in length? –More difficult in the E/R approach. We should access Movies to find those of over 150 mins. Then, we have to access Cartoons to see if they are cartoons. Then we should access MurderMysteries to find the weapon. –In OO approach we need only access Cartoon-MyrderMysteries table. However, we might want to use not too many tables. In the OO approach if we have a root and n children we need 2^n different tables!!! Examples

Null Values to Combine Relations If we are allowed to use NULL as a value in tuples, we can handle a hierarchy of classes with a single relation. –This relation has attributes for all the properties possessed by objects in any of the classes of the hierarchy. –An object is represented by a single tuple. This tuple has NULL in each attribute corresponding to a property that does not belong to the object’s class. If we apply this approach to the Movie hierarchy, we would create a single relation whose schema is: –Movie(title, year, length, filmType, studioName, starName, voice, weapon) –A movie like “Who Framed Roger Rabbit?”, being both a cartoon and a murdermystery, would be represented by several tuples that had no NULL’s. –The Little Mermaid, being a cartoon but not a murder-mystery, would have NULL in the weapon component.

Null Values to Combine Relations (Continued) It allows us to find all the information about an object in one relation. However, an approach using NULL’s is invalid for the relational model, although most of its commercial implementations support NULL’s.

Create Table CREATE TABLE Movies ( title CHAR(40), year INT, length INT, type CHAR(2) ); CREATE TABLE Studios ( name CHAR(20), address VARCHAR(255), noOfEmp INT ); CREATE TABLE Stars ( name CHAR(30), address VARCHAR(255), gender CHAR(1) ); CHAR(n) allocates a fixed space, and if the string that we store is shorter than n, then it is padded with blanks. Differently, VARCHAR(n) denotes a string of up to n characters. –ORACLE uses also VARCHAR2(n), which is semantically the same as VARCHAR(n), which is deprecated. –VARCHAR(n) or VARCHAR2(n) allow for compression in order to save space. Use CHAR(n) for frequently used fields, and use VARCHAR(n) otherwise.

Insert, Update, Delete, INSERT INTO Movies(title, year, length, type) VALUES('Godzilla', 1998, 120, 'C'); INSERT INTO Movies VALUES('Godzilla', 1998, 120, 'C'); UPDATE Movies SET title = 'Godzilla 2' WHERE title = 'Godzilla' AND year=1998; DELETE FROM Movies WHERE title='Godzilla 2';

Declaring primary keys DROP TABLE Movies; CREATE TABLE Movies ( title CHAR(40) PRIMARY KEY, year INT, length INT, type CHAR(2) ); DROP TABLE Movies; CREATE TABLE Movies ( title CHAR(40), year INT, length INT, type CHAR(2), PRIMARY KEY (title, year) );

Altering, Dropping, Defaults, Indexes ALTER TABLE Stars ADD phone CHAR(16); ALTER TABLE Stars DROP COLUMN gender; ALTER TABLE Stars MODIFY phone CHAR(26); DROP TABLE Stars; DROP TABLE Movies; DROP TABLE Studios; CREATE TABLE Stars ( name CHAR(30), address VARCHAR(255), gender CHAR(1) DEFAULT 'N' );

Declaring foreign keys CREATE TABLE Studios ( name CHAR(20) PRIMARY KEY, address VARCHAR(255), noOfEmp INT ); CREATE TABLE Movies ( title CHAR(40) PRIMARY KEY, year INT, length INT, type CHAR(2), studioName CHAR(20), FOREIGN KEY (studioName) REFERENCES Studios(name) );