CIS611 Lab Assignment 1 SS Chung

Similar documents
Part 1 on Table Function

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

Session Active Databases (2+3 of 3)

Database design process

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

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

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

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

Overview Relational data model

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

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

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

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

Database Technology. Topic 3: SQL. Olaf Hartig.

Course Notes on Relational Algebra

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

COSC Assignment 2

DEPARTMENT DNAME DNUMBER MGRNAME MGRSTARTDATE

In Chapters 3 through 6, we presented various aspects

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

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

SQL STRUCTURED QUERY LANGUAGE

Relational Calculus: 1

ECE 650 Systems Programming & Engineering. Spring 2018

Practical Project Report

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

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

SQL: A COMMERCIAL DATABASE LANGUAGE. Data Change Statements,

ECE 650 Systems Programming & Engineering. Spring 2018

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

CS5300 Database Systems

A taxonomy of SQL queries Learning Plan

CSC 742 Database Management Systems

CHAPTER 4. Relational Database Management Systems: MySQL

Relational Algebra 1

Data Definition Language (DDL)

SQL. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe

Advanced Database Models

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

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

SQL Introduction. CS 377: Database Systems

Chapter 8: Relational Algebra

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

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

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

SQL- Updates, Asser0ons and Views

Relational Algebra Part I. CS 377: Database Systems

DBMS LAB SESSION PAVANKUMAR MP

Course Notes on From Entity-Relationship Schemas to Relational Schemas

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

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

Slides by: Ms. Shree Jaswal

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

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

Relational Databases

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

The Relational Data Model and Relational Database Constraints

RELATIONAL DATA MODEL

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

Basic SQL II. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

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

APPENDIX. An Overview of the Hierarchical Data Model

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

CS430 Final March 14, 2005

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

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

This chapter discusses how to design a relational

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

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

Relational Model. CS 377: Database Systems

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

SQL: A COMMERCIAL DATABASE LANGUAGE. Complex Constraints

CSIE30600 Database Systems Basic SQL 2. Outline

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

Insertions, Deletions, and Updates

Selections. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 22, 2014

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

Data Manipulation Language (DML)

CHAPTER 3. Relational Database Management Systems: Oracle. 3.1 COMPANY Database

COSC344 Database Theory and Applications. COSC344 Lecture 15 1

CIS430 /CIS530 Lab Assignment 6

DATABASE MANAGEMENT SYSTEMS

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe Slide 25-1

Relational Algebra & Calculus. CS 377: Database Systems

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

The Enhanced ER Model

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

Chapter 6 - Part II The Relational Algebra and Calculus

Government of Karnataka Department of Technical Education Bengaluru

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

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

The Mixed Ontology Building Methodology Using Database Information

Chapter 3. Algorithms for Query Processing and Optimization

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

Database Lab#9 Connecting to postgresql database from java programs

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

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

Transcription:

CIS611 Lab Assignment 1 SS Chung 1. Creating a Relational Database Schema from ER Diagram, Populating the Database and Querying Over the database with SQL 2. Automatic Creation and Maintenance of Database from Web Interface 3. Transforming a SQL Query into an Execution Plan in Relational Algebra for Query Processing For those who have never taken CIS430/530: Part 1, Part 2, Part 3, and Part 4 are required as Lab1. For those who have taken CIS430/530: Part 3, Extra Part3, and Part 4 are required as Lab1. 1. Creating the COMPANY database schema using SQL (DDL) statements. The COMPANY database schema is depicted in the Figure 5.7 in the back of this lab. Core data for this database is shown in the Figure in the back as well. Write the corresponding SQL commands (DDL) to create all 6 Tables as shown in Figure 5.7. The typical SQL commands (DDL) for this lab are as follow: Drop table Employee; Create table Employee (...); ALTER TABLE EMPLOYEE ADD COLUMN ALTER TABLE EMPLOYEE ADD CONSTRAINT ALTER TABLE EMPLOYEE DROP COLUMN ; ALTER TABLE EMPLOYEE DROP CONSTRAINT ; ALTER TABLE EMPLOYEE ALTER COLUMN ; Select * From Employee; Tips: Create each table first without PK-FK Constraint, and populate tables with initial data. Then add each PK-FK Constraint with Alter table command. 2. Populating the COMPANY database using SQL (DML) statements. The typical SQL commands (DML) to populate a table and show the rows inserted into the table for this task are like the following example. INSERT INTO EMPLOYEE VALUES('John','B','Smith','123456789','9-Jan-55','731 Fondren, Houston, TX','M',30000,'987654321',5); Select * From Employee;

Show your SQL statements and the result in a Word document. Add screenshots showing your SQLs and the results to show the content of each table after populating it. 3. Write SQL as follow: Part1 on View: 1-1) Create a view named VDept_Budget that reports headcount for each department. The report includes 3 columns as follow: Dept_Name, Dept_Number, No_Emp. Include all the departments. Show the content of the view through SQL (Select * from VDept_Budget;) 1-2) Add yourself to the database (to Employee table). Then Show the content of your view again to see if your view is updated according to the changes in its base table Employee. 1-3) Then Change your view to add two more info Sum_Salary, Ave_Salary for each department. Include all the departments. Your report (view) lists 5 Columns as follow: Dept_Name, Dept_Number, No_Emp, Sum_Salary, Ave_Salary Show the content of your changed view to report the updated info after changes in the view and the database. Show your SQL statements and the result of each step in a Word document. Add screenshots showing your SQLs and the results to show your report is updated before and after the changes in the database. Part 2_1 on Stored Procedure 1: Create Stored Procedure SP_ Dept_Productivity that does the following tasks: 1. It creats a new table Dept_Productivity The table has 5 Columns as follow: Dept_Name, Dept_Number, EmpCount, Sum_Salary, ProjectCount Use Create Table without any constraints. 2. Use Insert Select to populate the table. Write Select query to join with the View VDept_Budget that you created in Part 1-3) to list Employee Headcount, Sum of Salary, The Number of the Projects that each department controls with dnumber and dname for each department.

PopuIate the table with Insert Select. Include all the departments in the list. 3. Show the content of the table with (Select * from Dept_Productivity;) Execute your stored procedure to get the output with Exec SP_Dept_Productivity ; Output (snapshot of screen) each part to show the creation of the View and the updated Views, the contents of the view and the updated view for the Part 1. For Part 2, Screenshot for each step to show Creation of the Stored Procedure, and Execution the SP to show the contents of the new table. Part 2_2 on Stored Procedure 2: Write a Stored Procedure SP_Report_ NEW_Budget using the view you created in Part 1-3). Use Cursor for this task. Your Stored Procedure SP_Report_ NEW_Budget does the following tasks: It creates a new table NEW_Dept_Budget as follow: NEW_Dept_Budget has 5 columns Dept_No (Int) Dept_Name (Char(30)) COUNT_Emp (INT) New_SUM_Salary (INT) New_AVE_Salary (INT) 1) Check if the view VDept_Budget is empty or not (by counting rows from the view). 2) If not empty, For each row of the view VDept_Budget, Calculate New_SUM_Salary, New_AVE_Salary as follow: If Dept = 1, Increase SUM(salary) 10% If Dept = 4, Increase SUM(salary) 20% If Dept = 5, Increase SUM(salary) 30% If Dept = 7, Increase SUM(salary) 40% 3) Insert each column value into the new table NEW_Dept_Budget. Output (snapshot of screen) each Function and Procedure created and Show all the tables contents with Select statement in your output.

For those who have taken CIS430/530, Part 3, Extra Part3, and Part 4 are required as Lab1. Part 3 on Table Function 1. Write a Table Function Total_Salary_By_Dept that returns a table Total_Salary_By_Dept _Table with Five column info as follow: It returns Total_Salary_By_Dept _Table that has the following Five column values. Dept_No (Int) Dept_Name (Char(30)) COUNT_Emp (INT) SUM_Salary (INT) AVE_Salary (INT) From underlying Company database 2. Write a Stored Procedure Report_ NEW_Total_Salary_By_Dept using (by calling) the Table Function Total_Salary_By_Dept, the one that was created in the part 1. Use CURSOR to write the Stored Procedure. Your Stored Procedure Report_ NEW_Total_Salary_By_Dept does the following tasks: It returns a new table NEW_Total_Salary_By_Dept as follow: NEW_Total_Salary_By_Dept has 7 columns Dept_No (Int) Dept_Name (Char(30)) COUNT_Emp (INT) SUM_Salary (INT) AVE_Salary (INT) New_SUM_Salary (INT) New_AVE_Salary (INT) 1) Check if the table Total_Salary_By_Dept _Table is empty or not. 2) If not empty, For each row of the table Total_Salary_By_Dept _Table, Calculate New_SUM_Salary, New_AVE_Salary as follow: If Dept = 1, Increase SUM(salary) 10% If Dept = 4, Increase SUM(salary) 20% If Dept = 5, Increase SUM(salary) 30% If Dept = 7, Increase SUM(salary) 40%

3) Insert each column value into the new table NEW_Total_Salary_By_Dept Output (snapshot of screen) each Function and Procedure created and Show all the tables contents with Select statement in your output. Extra Part 3: Required For those who have taken CIS430/530 Extra Credit For those who have never taken CIS430/530 For this part, you can use any language of your choice with your choice of a Platform: C#/Java with SQL Server or PHP with MYSQL on WAMP. See the example codes on the class webpage for these. 1. Create a company webpage where a new employee can add his/her information into the Employee table by taking a new employee information with 9 Input Boxes for each column Fname, MInit, Lname,, Dno as in Employee table schema With ADD button. 2. Write an Application Program that takes the new employee s input from the webpage and call a Stored Procedure SP_Insert_NewEmployee with the 9 input parameters. 3. Create the Stored Procedure SP_Insert_NewEmployee in your Database Server that performs: 3-1. Takes 9 inputs to Insert a new employee tuple into the Employee table 3-2. Find all the projects that are controlled by the department that the new employee works for. 3-3. Add all the project numbers with the new employee into Works_On table. Output (snapshot of screen) of Webpage and Stored Procedure created and Show all the tables contents with Select statement in your output.

Part 4: 4. Update the following new changes into the database: 1) Joyce English with Ssn = 453453453 got married with John Anderson. 2) Jenifer Wallace with Ssn = 987654321 just had a new daughter named Erica. 3) Jenifer Wallace with Ssn = 987654321 is just assigned to a new project number 10 and 10 hours to work on. Add these new entries into Dependent, Works_On tables in your database then Select * from Dependent and Select * from Works_On to show the updated table contents. 5. Write SQL Select statements to retrieve data in the followings: Q1: Make a list of all project numbers that Research department employees are working on, either as a worker or as a manager of the department that controls the projects. Write Q1 in Relational Algebra: Q2: Get SSN and the last name of married female employees who work on three or more projects Write Q2 in Relational Algebra: Q3. Write SQL using View instead of Subquery to express the subquery Q2. Q4: Get the Last and the First name of married employees who only have daughters. (Hint: Identify the following three sets in SQL first then write a main SQL using them. Married = Select ESSN From Dependent Where relationship = spouse ; Girls = Select ESSN From Dependent Where relationship = daughter ; Boys = Select ESSN From Dependent Where relationship = son ; Q4 in Relational Algebra: Q4 in Relational Tuple Calculus:

COMPANY DATABASE EMPLOYEE FNAME MINIT LNAME SSN BDATE ADDRESS SEX SALARY SUPERSSN DNO John B Smith 123456789 09-Jan-55 731 Fondren, Houston, TX M 30000 987654321 5 Franklin T Wong 333445555 08-Dec-45 638 Voss, Houston, TX M 40000 888665555 5 Joyce A English 453453453 31-Jul-62 5631 Rice, Houston, TX F 25000 333445555 5 Ramesh K Narayan 666884444 15-Sep-52 975 Fire Oak, Humble, TX M 38000 333445555 5 James E Borg 888665555 10-Nov-27 450 Stone, Houston, TX M 55000 1 Jennifer S Wallace 987654321 20-Jun-31 291 Berry, Bellaire, TX F 43000 888665555 4 Ahmad V Jabbar 987987987 29-Mar-59 980 Dallas, Houston, TX M 25000 987654321 4 Alicia J Zelaya 999887777 19-Jul-58 3321 Castle, SPring, TX F 25000 987654321 4 DEPARTMENT DNAME DNUMBER MGRSSN MGRSTARTDATE Headquarters 1 888665555 19-Jun-71 Administration 4 987654321 01-Jan-85 Research 5 333445555 22-May-78 Automation 7 123456789 06-Oct-05 DEPENDENT ESSN DEPENDENT_NAME SEX BDATE RELATIONSHIP 123456789 Alice F 31-Dec-78 Daughter 123456789 Elizabeth F 05-May-57 Spouse 123456789 Michael M 01-Jan-78 Son 333445555 Alice F 05-Apr-76 Daughter 333445555 Joy F 03-May-48 Spouse 333445555 Theodore M 25-Oct-73 Son 987654321 Abner M 29-Feb-32 Spouse DEPT_LOCATIONS DNUMBER DLOCATION 1 Houston 4 Stafford 5 Bellaire 5 Sugarland 5 Houston PROJECT PNAME PNUMBER PLOCATION DNUM ProductX 1 Bellaire 5 ProductY 2 Sugarland 5 ProductZ 3 Houston 5 Computerization 10 Stafford 4 Reorganization 20 Houston 1 Newbenefits 30 Stafford 4 WORKS_ON ESSN PNO Hours 123456789 1 32.5 123456789 2 7.5 333445555 2 10 333445555 3 10 333445555 10 10 333445555 20 10 453453453 1 20 453453453 2 20 666884444 3 40 888665555 20 987654321 20 15 987654321 30 20 987987987 10 35 987987987 30 5 999887777 10 10 999887777 30 30