Query 2: Pnumber Dnum Lname Address Bdate 10 4 Wallace 291 Berry, Bellaire, TX Wallace 291 Berry, Bellaire, TX

Similar documents
Part 1 on Table Function

CIS611 Lab Assignment 1 SS Chung

Database design process

COSC344 Database Theory and Applications. σ a= c (P) S. Lecture 4 Relational algebra. π A, P X Q. COSC344 Lecture 4 1

Session Active Databases (2+3 of 3)

Some different database system architectures. (a) Shared nothing architecture.

Advanced Databases. Winter Term 2012/13. Prof. Dr. Dietmar Seipel University of Würzburg. Advanced Databases Winter Term 2012/13

Querying a Relational Database COMPANY database For Lab4, you use the Company database that you built in Lab2 and used for Lab3

Dr. Anis Koubaa. Advanced Databases SE487. Prince Sultan University

Overview Relational data model

Course Notes on Relational Algebra

Introduction to SQL. ECE 650 Systems Programming & Engineering Duke University, Spring 2018

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

Database Technology. Topic 3: SQL. Olaf Hartig.

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

ECE 650 Systems Programming & Engineering. Spring 2018

CSC 742 Database Management Systems

Chapter 8. Joined Relations. Joined Relations. SQL-99: Schema Definition, Basic Constraints, and Queries

Database Technology. Topic 2: Relational Databases and SQL. Olaf Hartig.

Relational Algebra 1

In Chapters 3 through 6, we presented various aspects

COSC344 Database Theory and Applications. Lecture 6 SQL Data Manipulation Language (1)

Announcement5 SQL5. Create%and%drop%table5. Basic%SFW%query5. Reading%a%table5. TDDD37%% Database%technology% SQL5

Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries

ECE 650 Systems Programming & Engineering. Spring 2018

Relational Calculus: 1

L130 - DATABASE MANAGEMENT SYSTEMS LAB CYCLE-1 1) Create a table STUDENT with appropriate data types and perform the following queries.

CS 348 Introduction to Database Management Assignment 2

SQL. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe

Advanced Databases (SE487) Prince Sultan University College of Computer and Information Sciences

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

SQL: A COMMERCIAL DATABASE LANGUAGE. Data Change Statements,

Relational Model. CS 377: Database Systems

COSC Assignment 2

CS5300 Database Systems

Homework #4 1. Suppose that each of the following Update operations is applied directly to the database state shown in Figure 5.6.

SQL STRUCTURED QUERY LANGUAGE

SQL- Updates, Asser0ons and Views

A taxonomy of SQL queries Learning Plan

Chapter 8: Relational Algebra

SQL: Advanced Queries, Assertions, Triggers, and Views. Copyright 2012 Ramez Elmasri and Shamkant B. Navathe

Information Systems Development 37C Lecture: Final notes. 30 th March 2017 Dr. Riitta Hekkala

SQL-99: Schema Definition, Basic Constraints, and Queries. Create, drop, alter Features Added in SQL2 and SQL-99

Practical Project Report

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

DEPARTMENT DNAME DNUMBER MGRNAME MGRSTARTDATE

Relational Algebra Part I. CS 377: Database Systems

UNIVERSITY OF TORONTO MIDTERM TEST SUMMER 2017 CSC343H Introduction to Databases Instructor Tamanna Chhabra Duration 120 min No aids allowed

NOTE: DO NOT REMOVE THIS EXAM PAPER FROM THE EXAM VENUE

SQL Introduction. CS 377: Database Systems

Integrity Coded Relational Databases (ICRDB) - Protecting Data Integrity in Clouds

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore ) Department of MCA. Solution Set - Test-II

Chapter 3. Algorithms for Query Processing and Optimization

Data Definition Language (DDL)

Simple SQL Queries (contd.)

Chapter 6 - Part II The Relational Algebra and Calculus

Relational Model and Relational Algebra. Slides by: Ms. Shree Jaswal

SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT

Advanced Database Models

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

DATABASE CONCEPTS. Dr. Awad Khalil Computer Science & Engineering Department AUC

Chapter 6 The Relational Algebra and Calculus

COSC344 Database Theory and Applications. COSC344 Lecture 15 1

Slides by: Ms. Shree Jaswal

SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT

More SQL: Complex Queries, Triggers, Views, and Schema Modification

RELATIONAL DATA MODEL

The Relational Data Model and Relational Database Constraints

Views. Lecture 15 Section 5.3. Robb T. Koether. Hampden-Sydney College. Mon, Feb 18, 2013

Views. Lecture 15 Section 5.3. Robb T. Koether. Hampden-Sydney College. Mon, Feb 18, 2013

Relational Databases

Algorithms for Query Processing and Optimization. 0. Introduction to Query Processing (1)

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

Guides for Installing MS SQL Server and Creating Your First Database. Please see more guidelines on installing procedure on the class webpage

Chapter 8: The Relational Algebra and The Relational Calculus

State your dream system (use the following materials, if you need) Alliance model character year character 4. A/T description character 51

This chapter discusses how to design a relational

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

The Relational Algebra and Calculus. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe

DBMS LAB SESSION PAVANKUMAR MP

SQL: A COMMERCIAL DATABASE LANGUAGE. Complex Constraints

Outline. Textbook Chapter 6. Note 1. CSIE30600/CSIEB0290 Database Systems Basic SQL 2

CSIE30600 Database Systems Basic SQL 2. Outline

Chapter 6 5/2/2008. Chapter Outline. Database State for COMPANY. The Relational Algebra and Calculus

Views. Lecture 15. Robb T. Koether. Fri, Feb 16, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) Views Fri, Feb 16, / 28

Ref1 for STUDENT RECORD DB: Ref2 for COMPANY DB:

UNIT-V SQL Explain insert, delete and update statements in SQL with example.

Aggregation. Lecture 7 Section Robb T. Koether. Hampden-Sydney College. Wed, Jan 29, 2014

Mobile and Heterogeneous databases Distributed Database System Query Processing. A.R. Hurson Computer Science Missouri Science & Technology

MIT Database Management Systems Lesson 03: ER-to-Relational Mapping

Relational Algebra & Calculus. CS 377: Database Systems

Chapter 19 Query Optimization

Outline. Note 1. CSIE30600 Database Systems More SQL 2

Database Systems External Sorting and Query Optimization. A.R. Hurson 323 CS Building

CS 338 Basic SQL Part II

Insertions, Deletions, and Updates

Course Notes on From Entity-Relationship Schemas to Relational Schemas

More SQL: Complex Queries, Triggers, Views, and Schema Modification

Transcription:

5.11 No violation, integrity is retained. Dnum = 2 does not exist. This can be solved by adding a foreign key referencing the department table, so the operation does not execute. Dnum = 4 already exists, this is already enforced since Dnum is the primary key. Additionally, the Mgr_ssn: 943775543 does not exist in the employee table, thus not a valid employee, this can be enforced with Mgr_ssn being a foreign key referencing SSN in the employee table. The ESSN: 677678989, does not exist in the employee table, this can be fixed by using a foreign key to refer to SSN in employee. Also Pno cannot be NULL since it is part of the primary key, this must have a unique value. No violation. f) No violation g) Integrity violated because ESSN in Works_on and Dependent both refer to SSN in Employee (ESSN in both tables are foreign keys referencing SSN), deleting that employee leaves 2 foreign keys with no primary to refer to. To fix this a CASCADE or RESTRICT operation can be implemented in the SQL command to either delete all referencing tuples or keep all the data. h) Integrity violated, Pno in Works_on is a foreign key referencing Pnumber in Project. To fix this we can add the CASCADE or RESTRICT function. i) No violation j) The SSN 943775543 does not exist in the SSN attribute column. This is already enforced and would not execute anyways, k) No violation. 5.13 The candidate key should be unique so we have a few options as stated below -Univ_Section# -Composite keys, there can be many, but just to name a few: -(Course#, Room#, Time_perio -(Course#, Instructor_name, Time_perio -(Building_code, Room#, Time_perio 5.14 Foreign Key Order# in ORDER_ITEM Item# in ORDER_ITEM Order# in SHIPMENT Warehouse# in SHIPMENT Cust# in ORDER Referencing Primary Key Order# in ORDER Item# in ITEM Order# in ORDER Wharehouse# in WHAREHOUSE Cust# in CUSTOMER A possible constraint can be that a City can be added ORDER and Cust# can be added to WHAREHOUSE, then in CUSTOMER, Cust# and City can be used as a composite primary key so orders can be shipped from the closest possible wharehouse.

8.15 Query 1: Address John Smith 731 Fondren, Houston, TX Franklin Wong 638 Voss, Houston, TX Ramesh Narayan 975 Fire Oak, Humble, TX Joyce English 5631 Rice, Houston, TX Query 2: Pnumber Dnum Address Bdate 10 4 Wallace 291 Berry, Bellaire, TX 1941-06-20 30 4 Wallace 291 Berry, Bellaire, TX 1941-06-20 Query 3: Empty/null result Query 4: Pno 1 2 Query 5: Smith Wong Query 6: Narayan Zelaya Borg English Jabber Query 7: Wong Wallace John Franklin Ramesh Alicia James Joyce Ahmed Franklink Jennifer

8.16 emp1 <- employee ssn=essn works_on Pno=pnumber project emp2 <- σ (dno=5 and pname= ProductX and hours>10.0) (emp1) fin_ans <- π fname,minit,lname (emp2) emp_deps,_ employee fin_ans <-π (fname,minitlnam (emp_deps) (ssn=essn and fname = dependent_nam dependent wong_ssn <- π ssn (σ l(name= Wong and fname= Franklin ) (employe) fin_ans <- π fname,minit,lname (employee superssn=ssnwong_ssn) hours(pno,total_hours) <- pno F sum hours (works_on) fin_ans <- π pname,total_hours (hours pno=pnumber project) emp_proj(ssn,pnumber) <- π essn,pno (works_on) proj <- π pnumber projects fin_ans <- π fname,minit,lname ((emp_proj / proj) * employees) f) emp_proj(ssn) <- π essn (works_on) emp_proj_names <- emp_proj * employee fin_ans <- π fname,minit,lname (employees emp_proj_names) g) dept_avgsal(dnumber, avgsal) <- dno F avg salary (employe fin_ans <- π dname,avgsal (dep_avgsal * department) h) ans <- F avg salary (σ sex= female (employe)

i) emps_houston <- π fname,minit,lname,address (σ plocation= Houston (employee* (ssn),(essn) works_on* (pno),(p number)project)) dept_houston <- π fname,minit,lname,address (σ dlocation= Houston (employee* (dno),(dnumber) dept_locatio n)) ans <- emps_houston dept_houston j) dept_mgrs(ssn) <- π mgrssn (department) emps_with_deps(ssn) <- π essn (dependent) ans <- π fname,minit,lname (employee *(dept_mgrs emps_with_deps)) 8.19 W2_info <- π Warehouse# = W2 (Shipment) ans <- σ Order#, Ship_date (W2_info) JoseLopez <- π Cname = Jose Lopez (Order Customer) ans <- σ Order#, Warehouse# (Shipment JoseLopez) ans <- Cname F count (order#) as #oforders, avg(ord_amt) as Avg_Order_Amt (Customer Order) ans <- πorder#(σ (shipdate Odate 30(ORDER SHIPMENT)) NY_WH π City = "New York" (Warehous ans σ Order#, Warehouse# (Shipment) σ Warehouse# (NY_WH)

8.22 10 a 5 10 b 6 25 a 6 25 c 3 15 b 8 10 b 6 15 b 8 10 b 5 10 a 5 10 b 6 15 b 8 NULL NULL NULL 25 a 6 25 c 3 NULL NULL NULL 25 c 3 15 b 8 10 b 6 15 b 8 10 b 5 P Q R 10 a 5 15 b 8 25 a 6 10 b 6 25 c 3 10 b 5 f)