COP5725 – Principles of Database Management Systems

Slides:



Advertisements
Similar presentations
COP4540 Database Management System Midterm Review
Advertisements

Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
CSC343: Intro. to Databases1 Tutorial for CSC343 Introduction to Databases Fall 2006 Week 2.
Entity-Relationship (ER) Modeling
IS698: Database Management Min Song IS NJIT. The Relational Data Model.
COP-5725 Practice Exercises
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
The Entity-Relationship Model
(Uses slides from Fernando Farfan and Eduardo J. Ruiz
Entity-Relationship Models
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Ch5: ER Diagrams - Part 1 Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
1 The Entity-Relationship Model Chapter 2. 2 Overview of Database Design  Conceptual design: (ER Model is used at this stage.) –What are the entities.
Databases Revision.
1 Translation of ER-diagram into Relational Schema Prof. Sin-Min Lee Department of Computer Science.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
1 Data Modeling Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Entity Relationship Model Chapter 6. Basic Elements of E-R Model Entity Object of the real world that stores data. Eg. Customer, State, Project, Supplier,
DeSiamorewww.desiamore.com/ifm1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model  Vendors: IBM, Informix, Microsoft, Oracle, Sybase  Recent.
Chapter 2.  Conceptual design: (ER Model is used at this stage.) ◦ What are the entities and relationships in the enterprise? ◦ What information about.
1 Translation of ER-diagram into Relational Schema Prof. Sin-Min Lee Department of Computer Science.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
MIS 301 Information Systems in Organizations Dave Salisbury ( )
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
Assignements. CSC343: Intro. to Databases2 Exercise 1 Superkeys: Candidate keys: Primary key:
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.
The Relational Model1 ER-to-Relational Mapping and Views.
Database Management System Quiz 1. A company needs to store information about: the employees identified by EmpNo, Name, Salary and Phone; departments.
Msigwaemhttp//:msigwaem.ueuo.com/1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
Database Management Systems,1 Conceptual Design Using the Entity-Relationship (ER) Model.
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
CMPT 258 Database Systems The Relationship Model PartII (Chapter 3)
COMP3030 Database Management System Final Review
IS6145 Database Analysis and Design Lecture 4: Fine-Granular Design-Specific ER Modelling Rob Gleasure
MIS 301 Information Systems in Organizations Dave Salisbury ( )
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
The Relational Model Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY.
COP-5725 Practice Exercises
Ch 7: Normalization-Part 1
CSE 412/598 DATABASE MANAGEMENT COURSE NOTES 3. ENTITY-RELATIONSHIP CONCEPTUAL MODELING Department of Computer Science & Engineering Arizona State University.
Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 Mapping E/R Diagrams to Relational Database Schemas Second Half of Chapter.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Multi-billion dollar industry, $15+ bill in  Vendors:
COP Introduction to Database Structures
IS6145 Database Analysis and Design Lecture 4: Fine-Granular Design-Specific ER Modelling Rob Gleasure
Assignements.
The Entity-Relationship Model
SQL – Part 2.
COP Introduction to Database Structures
The Entity-Relationship Model
Translation of ER-diagram into Relational Schema
Question Which of the following plays an important role in representing information about the real world in a database? Explain briefly 1)DDL.
Question 01 A company database needs to store information about employees (identified by NIC, with salary and phone as attributes), departments (identified.
Translation of ER-diagram into Relational Schema
IS6125 Database Analysis and Design Lecture 6: Fine-Granular Design-Specific ER Modelling Rob Gleasure
Question Which of the following plays an important role in representing information about the real world in a database? Explain briefly 1)DDL.
Presentation transcript:

COP5725 – Principles of Database Management Systems Review by Eduardo J Ruiz (Adapted from Fernando Farfan Slides)

AGENDA Ch1. Overview of DBMSs Ch2. Database Design Ch3. Relational Model Ch4. Relational Algebra

AGENDA Ch1. Overview of DBMSs Ch2. Database Design Ch3. Relational Model Ch4. Relational Algebra

CH1 EXERCISES 1.4. Explain the difference between external, internal, and conceptual schemas. External schemas: Allow data access to be customized at the level of individual users or groups of users using different VIEWS of the same conceptual schema. Views are not stored in DBMS but they generated on-demand. Conceptual (logical) schemas: Describes all the data in terms of the data model. In a relational DBMS, it describes all relations stored. While there are several views for a given database, there is exactly one conceptual schema to all users. Internal (physical) schemas: Describes how the relations described in the conceptual schema are actually stored on disk (or other physical media).

CH1 EXERCISES Logical Data Independence Physical Data Independence 1.4. How are these different schema layers related to the concepts of logical and physical data independence? Logical Data Independence Protection from changes in Logical Structure of Data (The Conceptual Schema) Provided by External Schema (Views). Views definitions are updated on changes. The external schema definition are maintained (and more important the programs running on this schemas) Physical Data Independence Protection from changes in Physical Structure of Data A relation can be stored in different ways at the physical level .

CH1 EXERCISES Logical Independence Physical Independence Provider Providers (name, phone, contact) (name, phone, contact, zip, state) National Providers (name, phone, contact, zip, state, city) International Providers (name, phone code, phone, contact, country, city) Physical Conceptual Provider Heap Clustered Index

CH1 EXERCISES

CH2 Ch2. Database Design Ch1. Overview of DBMSs Ch3. Relational Model Ch4. Relational Algebra

CH2 - Concepts Domain Attribute Entity (Set) Relationship (Set) Key Candidate Primary Key Participation Constraint Key Constraint Aggregation Overlap Constraint Descriptive Attributes Roles One-to-Many Many-to-Many Weak Entity Set Identifying Owner/Relationship

CH2 EXERCISES 2.2. A university database contains information about professors (id. by SSN) and courses (id. by courseid). Professors teach courses; each of the following situations concerns the Teaches relationship set. For each situation, draw an ER diagram that describes it (assuming no further constraints hold). Professors can teach the same course in several semesters, and each offering must be recorded.

CH2 EXERCISES 2.2. CONT… Professors can teach the same course in several semesters, and only the most recent such offering needs to be recorded. (Assume this condition applies in all subsequent questions.)

CH2 EXERCISES 2.2. CONT… Every professor must teach some course.

CH2 EXERCISES 2.2. CONT… Every professor teaches exactly one course (no more, no less).

CH2 EXERCISES 2.2. CONT… Every professor teaches exactly one course (no more, no less), and every course must be taught by some professor.

CH2 EXERCISES 2.2. CONT… Certain courses can be taught by a team of professors jointly, but it is possible that no one professor in a team can teach the course. Model this situation, introducing additional entity sets and relationship sets if necessary.

CH2 EXERCISES Employees work in departments; 2.4 A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments (identified by dno, with dname and budget as attributes), and children of employees (with name and age as attributes). Employees work in departments; Each department is managed by an employee; A child must be identified uniquely by name when the parent (who is an employee; assume that only one parent works for the company) is known. We are not interested in information about a child once the parent leaves the company.

CH2 EXERCISES

CH2 EXERCISES 2.8 Galleries keep information about artists, their names (which are unique), birthplaces, age, and style of art. For each piece of artwork, the artist, the year it was made, its unique title, its type of art (e.g., painting, lithograph, sculpture, photograph), and its price must be stored. Pieces of artwork are also classified into groups of various kinds, for example, portraits, still lifes, works by Picasso, or works of the 19th century; a given piece may belong to more than one group. Each group is identified by a name (like those above) that describes the group. Finally, galleries keep information about customers. For each customer, galleries keep their unique name, address, total amount of dollars they have spent in the gallery (very important!), and the artists and groups of art that each customer tends to like.

CH2 EXERCISES

AGENDA Ch3. Relational Model & SQL Ch1. Overview of DBMSs Ch2. Database Design Ch3. Relational Model & SQL Ch4. Relational Algebra

CH3 - Concepts Table, Relation Relation Schema Attributes/Domain Relation Instance Tuple /Records Degree/Arity Cardinality Relational Database DDL Primary Key Superkey Candidate Key Foreign Key

CH3 EXERCISES 3.4. What is the difference between a candidate key and the primary key for a given relation? What is a superkey? The primary key is the key selected by the DBA from among the group of candidate keys, all of which uniquely identify a tuple. A superkey is a set of attributes that contains a key.

CH3 EXERCISES 3.8. Answer each of the following questions briefly. The questions are based on the following relational schema: Emp(eid: integer, ename: string, age: integer, salary: real) Works(eid: integer, did: integer, pcttime: integer) Dept(did: integer, dname: string, budget: real, managerid: integer) 1. Give an example of a foreign key constraint that involves the Dept relation. What are the options for enforcing this constraint when a user attempts to delete a Dept tuple? CREATE TABLE Works ( eid INTEGER NOT NULL , did INTEGER NOT NULL , pcttime INTEGER, PRIMARY KEY (eid, did), FOREIGN KEY (did) REFERENCES Dept ) (*)

CH3 EXERCISES OPTIONS for maintaining referential integrity ON DELETE { CASCADE, SET DEFAULT, SET NULL, NO ACTION} ON UPDATE { CASCADE, SET DEFAULT, SET NULL, NO ACTION}

CH3 EXERCISES 3.8. 2. Write the SQL statements required to create the preceding relations, including appropriate versions of all primary and foreign key integrity constraints. CREATE TABLE Emp ( eid INTEGER, ename CHAR(10), age INTEGER, salary REAL, PRIMARY KEY (eid) ) CREATE TABLE Works ( did INTEGER, pcttime INTEGER, PRIMARY KEY (eid, did), FOREIGN KEY (did) REFERENCES Dept ON DELETE CASCADE, FOREIGN KEY (eid) REFERENCES Emp ON DELETE CASCADE CREATE TABLE Dept ( budget REAL, managerid INTEGER , PRIMARY KEY (did), FOREIGN KEY (managerid) REFERENCES Emp ON DELETE SET NULL

CH3 EXERCISES 3.8. 3. Define the Dept relation in SQL so that every department is guaranteed to have a manager. CREATE TABLE Dept ( did INTEGER, budget REAL, managerid INTEGER NOT NULL , PRIMARY KEY (did), FOREIGN KEY (managerid) REFERENCES Emp )

CH3 EXERCISES 3.8. 4. Write an SQL statement to add John Doe as an employee with eid = 101, age = 32 and salary = 15, 000. INSERT INTO emp VALUES (101, ’John Doe’, 32, 15000) INSERT INTO emp (eid, ename, age, salary) VALUES (101, ’John Doe’, 32, 15000) (Basic Insertions)

CH3 EXERCISES 3.8. 5. Write an SQL statement to give every employee a 10 percent raise. UPDATE Emp E SET E.salary = E.salary * 1.10 UPDATE Emp E SET E.salary = E.salary * 1.10 WHERE E.ename= ’John Doe’,

CH3 EXERCISES 3.8. 6. Write an SQL statement to delete the Toy department. Given the referential integrity constraints you chose for this schema, explain what happens when this statement is executed. DELETE FROM Dept D WHERE D.dname = ’Toy’

AGENDA Ch4. Relational Algebra Ch1. Overview of DBMSs Ch2. Database Design Ch3. Relational Model Ch4. Relational Algebra

CH4 EXERCISES 4.2. Given two relations R1 and R2, where R1 contains N1 tuples, R2 contains N2 tuples, and N2 > N1 > 0, give the min and max possible sizes for the resulting relational algebra expressions:

CH4 EXERCISES 4.4. Consider the Supplier-Parts-Catalog schema. State what the following queries compute: Find the Supplier names of the suppliers who supply a red part that costs less than 100 dollars. This Relational Algebra statement does not return anything than 100 dollars and a green part that costs less than 100 dollars.

CH4 EXERCISES 4.4. Cont: Find the Supplier ids of the suppliers who supply a red part that costs less than 100 dollars and a green part that costs less than 100 dollars. Find the Supplier names of the suppliers who supply a red part that costs less than 100 dollars and a green part that costs less than 100 dollars.

CH4 EXERCISES 4.6. What is relational completeness? If a query language is relationally complete, can you write any desired query in that language? Relational completeness means that a query language can express all the queries that can be expressed in relational algebra. It does not mean that the language can express any desired query. Relational Algebra can’t represent Recursion

CH4 EXERCISES 4.3. Consider the Supplier-Parts-Catalog schema. State what the following queries compute: Write the following queries in relational algebra, tuple relational calculus, and domain relational calculus:

CH4 EXERCISES Find the names of suppliers who supply some red part. Find the sids of suppliers who supply some red part or are at 221 Packer Ave. Find the sids of suppliers who supply every red part. Find pairs of sids such that the supplier with the first sid charges more for some part than the supplier with the second sid. Find the pids of the most expensive parts supplied by suppliers named Yosemite Sham.

Questions? Eduardo Ruiz ECS-232 (> 1 pm ) Subject: COP-5725 <YOUR NAME>

Project Schema (18) Relational Schema Definition (15) Incomplete representation, wrong representation, Misapplied notation (-3) (-12) Schemas with diff notation that the one used in the book or handwritten diagrams (you will not graded until you present the digital format) Relational Schema Definition (15) SQL errors, consistency with the ER, missing constraints, normal form problems (-3) (-10) if you don’t use the INNODB engine

Project Data (5) View Definitions (12) Invalid Syntax (-2) SQL errors, consistency with the definition (-2) You must define the semantic for your proposed views (-2) Select count(*) queries (-1)

Project 40% penalty for late submissions (2 days max) Mail Title: COP5725 Project Submission -<Names> Hard Copy (can be printed at both sides)