Assignment # 2. Database Systems. Due Date: Tuesday, 11 November 2008

Similar documents
Chapter 1. Writing Basic. SQL Statements

Aggregating Data Using Group Functions

Displaying Data from Multiple Tables

Displaying Data from Multiple Tables. Chapter 4

Examine the structure of the EMPLOYEES table: EMPLOYEE_ID NUMBER Primary Key FIRST_NAME VARCHAR2(25) LAST_NAME VARCHAR2(25)

Producing Readable Output with SQL*Plus

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Subqueries Chapter 6

ComponentNo. C_Description UnitOfMeasure. C_Quantity

SQL Introduction Chapter 7, sections 1 & 4. Introduction to SQL. Introduction to SQL. Introduction to SQL

Oracle/SQL Tutorial 1

Data Models and Database Management Systems (DBMSs) Dr. Philip Cannata

SQL> SELECT ename, job, sal Salary. 1.4.Will the SELECT statement execute successfully? True/False

Analysis One Code Desc. Transaction Amount. Fiscal Period

RDBMS Using Oracle. Lecture Week 7 Introduction to Oracle 9i SQL Last Lecture. kamran.munir@gmail.com. Joining Tables

AT&T Global Network Client for Windows Product Support Matrix January 29, 2015

Oracle For Beginners Page : 1

SQL*Plus User s Guide and Reference

COMPARISON OF FIXED & VARIABLE RATES (25 YEARS) CHARTERED BANK ADMINISTERED INTEREST RATES - PRIME BUSINESS*

COMPARISON OF FIXED & VARIABLE RATES (25 YEARS) CHARTERED BANK ADMINISTERED INTEREST RATES - PRIME BUSINESS*

Displaying Data from Multiple Tables. Copyright 2006, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Relational Algebra. Query Languages Review. Operators. Select (σ), Project (π), Union ( ), Difference (-), Join: Natural (*) and Theta ( )

CSC 443 Fall 2011 Dr. R. M. Siegfried. Answers to Assignment #1

Appendix A Practices and Solutions

MONASH UNIVERSITY. Faculty of Information Technology

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

Case 2:08-cv ABC-E Document 1-4 Filed 04/15/2008 Page 1 of 138. Exhibit 8

Lab # 5. Retreiving Data from Multiple Tables. Eng. Alaa O Shama

Procedural Extension to SQL using Triggers. SS Chung

Enhanced Vessel Traffic Management System Booking Slots Available and Vessels Booked per Day From 12-JAN-2016 To 30-JUN-2017

Conversion Functions

Accident & Emergency Department Clinical Quality Indicators

Access Tutorial 2: Tables

DECLARATION SECTION. BODY STATEMENTS... Required

Displaying Data from Multiple Tables

Date / Time Arithmetic with Oracle

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved.

Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved.

Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)

2. DECODE Function, CASE Expression

Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query

The join operation allows you to combine related rows of data found in two tables into a single result set.

Chapter 1 Overview of the SQL Procedure

Microsoft Access Lesson 5: Structured Query Language (SQL)

CIS 631 Database Management Systems Sample Final Exam

GUJARAT TECHNOLOGICAL UNIVERSITY

There are five fields or columns, with names and types as shown above.

Lab Manual. Database Systems COT-313 & Database Management Systems Lab IT-216

Salary. Cumulative Frequency

Where? Originating Table Employees Departments

IBM DB Introduction to SQL and database objects Hands-on Lab. Information Management Cloud Computing Center of Competence.

Unit 10: Microsoft Access Queries

Financial Data Access with SQL, Excel & VBA

Database Administration with MySQL

CMU - SCS / Database Applications Spring 2013, C. Faloutsos Homework 1: E.R. + Formal Q.L. Deadline: 1:30pm on Tuesday, 2/5/2013

CENTERPOINT ENERGY TEXARKANA SERVICE AREA GAS SUPPLY RATE (GSR) JULY Small Commercial Service (SCS-1) GSR

3.GETTING STARTED WITH ORACLE8i

Oracle Database 10g Express

ABSORBENCY OF PAPER TOWELS

Assignment 4 CPSC 217 L02 Purpose. Important Note. Data visualization

GET DATA FROM MULTIPLE TABLES QUESTIONS

Consumer ID Theft Total Costs

P/T 2B: 2 nd Half of Term (8 weeks) Start: 25-AUG-2014 End: 19-OCT-2014 Start: 20-OCT-2014 End: 14-DEC-2014

P/T 2B: 2 nd Half of Term (8 weeks) Start: 26-AUG-2013 End: 20-OCT-2013 Start: 21-OCT-2013 End: 15-DEC-2013

P/T 2B: 2 nd Half of Term (8 weeks) Start: 24-AUG-2015 End: 18-OCT-2015 Start: 19-OCT-2015 End: 13-DEC-2015

Installation Guide (MS Outlook Express)

Objectives. Oracle SQL and SQL*PLus. Database Objects. What is a Sequence?

Grade 6 Math Circles. Binary and Beyond

Graham Kemp (telephone , room 6475 EDIT) The examiner will visit the exam room at 15:00 and 17:00.

The Entity-Relationship Model

Ashley Institute of Training Schedule of VET Tuition Fees 2015

Using TimesTen between your Application and Oracle. between your Application and Oracle. DOAG Conference 2011

Access to Relational Databases Using SAS. Frederick Pratter, Destiny Corp.

SQL Server Databases Tutorial

VARRAY AND NESTED TABLE

Introduction to Querying & Reporting with SQL Server

CHAPTER 3: DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL

Information Technology

2. Which of the following declarations is invalid? Mark for Review (1) Points

The New Prior Approval Rate Application Process Frequently Asked Questions

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

An Oracle White Paper August Express Mode Loading with SQL*Loader in Oracle Database 12c

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

ITP 300: Database Web Development. Database Web Development (Monday section) Fall 2012 Course Units

D B M G Data Base and Data Mining Group of Politecnico di Torino

Annual Report Interdisciplinary Studies B.A., B.S., M.A., M.S.

Writing Control Structures

In this session, we use the table ZZTELE with approx. 115,000 records for the examples. The primary key is defined on the columns NAME,VORNAME,STR

DbSchema Tutorial with Introduction in SQL Databases

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

How to Write a Formal Report

Using AND in a Query: Step 1: Open Query Design

Introduction to PL/SQL Programming

Accounts Receivable: Importing Remittance Data

Database CIS 340. lab#6. I.Arwa Najdi

How To Name A Program In Apl/Sql

Transcription:

Assignment # 2 Database Systems Due Date: Tuesday, 11 November 2008 Roll No Name Signature

PART 1 THE SAMPLE TABLES EMP EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7369 SALMAN CLERK 7902 17 DEC 2000 8000 20 7499 ALIA SALESMAN 7698 20 FEB 2001 16000 3000 30 7521 WAHEED SALESMAN 7698 22 FEB 2001 12500 5000 30 7566 JAMIL MANAGER 7839 02 APR 2001 29750 20 7654 MEHVISH SALESMAN 7698 28 SEP 2001 12000 12500 30 7698 BILAL MANAGER 7839 01 MAY 2001 28500 30 7782 QASIM MANAGER 7839 09 JUN 2001 24500 10 7788 SHAMS ANALYST 7566 09 DEC 2002 30000 20 7839 KAMRAN PRESIDENT 17 NOV 2001 50000 7844 TANVEER SALESMAN 7698 08 SEP 2001 15000 0 30 7876 AFTAB CLERK 7788 12 JAN 2003 11000 20 7900 JAVERIA CLERK 7698 03 DEC 2001 9500 30 7902 FOZIA ANALYST 7566 03 DEC 2001 30000 20 7934 MURAD CLERK 7782 23 JAN 2002 13000 10 DEPT DEPTNO DNAME LOC 10 ACCOUNTING ISLAMABAD 20 RESEARCH KARACHI 30 SALES LAHORE 40 OPERATIONS QUETTA SALGRADE GRADE LOSAL HISAL 1 7000 12000 2 12010 14000 3 14010 20000 4 20010 30000 5 30010 99990

EXERCISES 1 Predict what results will be obtained by joining the EMP and DEPT tables without specifying any selection criteria, then try it out. How many rows does the result produce? 2 Repeat B1 but this time joining EMP to itself. Look carefully at the output to make sure you understand it. (Ensure that you do have results table and not an error message!! 3 Find the name and salary of employees in Karachi. 4 Produce a list that will show the salary grade each employee is on. Display the name, job, salary and grade with the output in ascending order of salary, with those on the same salary ordered alphabetically. 5 Display employee name, job, salary and department name for those on grade 3. 6 Display details of employees in ACCOUNTING. (Don t answer this by finding who is in department number 10.) 7 Show the name, employee number and manager's name of those who are managed by either Bilal or Jamil. 8 Display the employee name, location and department name of those whose salary is greater than 15000. 9 What are the lowest and highest basic salaries within the company? 10 How many people have a salary greater than 20000? 11 How many people are there in ACCOUNTING? Don t work out how many people there are in department 10! NULL Values If a column has no value for any particular row, it is referred to as a NULL value. This is not the same as a zero in a numeric column, or a space in a character column. In MS SQL Server, the IsNull function can be used to convert a null into a specified value e.g. IsNull(COMM, 0) will return the actual value of COMM if it has a value, or a zero if COMM is null. This is often necessary when performing calculations, or formatting for output since null values will be totally ignored by many functions and operations. A column can be tested using IS NULL or IS NOT NULL e.g. SELECT...FROM... WHERE column_name IS NOT NULL; 12 What are the highest and lowest incomes (i.e. to include commission) in the Sales Department?

GROUPING DATA The GROUP BY clause splits the table into specified groups, returning one summary row for each group which is then used in the SELECT clause. In each of the following queries, you may treat the President as not an employee (as he isn t given a deptno). However, here s a question for the sharper ones: how your queries change if you did need to include him as an employee? 13 How many people are there in each department? 14 How many people are there in each type of job in each department? 15 For each department, find the average salary and the total salary bill excluding commission. 16 Find the maximum commission earned, and the number of people in each department. THE HAVING CLAUSE. The HAVING clause is used to specify which GROUPS are to be displayed. WHERE restricts which rows a SELECT works on and HAVING restricts which groups. 17 Display the department name and number of employees in departments with fewer than 6 employees. 18 Display the names of all the people in a management position, their department name and the number of staff for whom they have direct responsibility. (This is not simply asking for departmental managers.)

PART 2 1. Draw an E R diagram for each of the following situations (if you believe that you need to make additional assumptions, clearly state them for each situation): a. A company has a number of employees. The attributes of EMPLOYEE include Employee_ID (identifier), Name, Address, and Birthdate. The company also has several projects. Attributes of PROJECT include Project_ID (identifier), Project_Name, and Start_Date. Each employee may be assigned to one or more projects, or may not be assigned to a project. A project must have at least one employee assigned, and may have any number of employees assigned. An employee's billing rate may vary by project and the company wishes to record the applicable billing rate for each employee when assigned to a particular project. Do the attribute names in this description follow the guidelines for naming attributes? If not, suggest better names. b. A university has a large number of courses in its catalog. Attributes of COURSE include Course_Number (identifier), Course_Name, and Units. Each course may have one or more different courses as prerequisites, or may have no prerequisites. Similarly, a particular course may be a prerequisite for any number of courses, or may not be prerequisite for any other course. Provide a good definition of COURSE, Why is your definition a good one? c. A laboratory has several chemists who work on one or more projects. Chemists also may use certain kinds of equipment on each project. Attributes of CHEMIST include EmployeeJD (identifier), Name, and Phone_No. Attributes of PROJECT include ProjectJD (identifier) and Start_Date. Attributes of EQUIPMENT include Serial_No and Cost. The organization wishes to record Assign_Date that is, the date when a given equipment item was assigned to a particular chemist working on a specified project. A chemist must be assigned to at least one project and one equipment item. A given equipment item need not be assigned, and a given project need not be assigned either a chemist or an equipment item. Provide good definitions for all of the relationships in this situation. d. A college course may have one or more scheduled sections, or may not have a scheduled section. Attributes of COURSE include Course ID, Course_Name, and Units. Attributes of SECTION include Section_Number and Semester_ID. Sernester_ID is composed of two parts: Semester and Year. Section_Number is an integer (such as "1" or "2") that distinguishes one section from another for the same course but does not uniquely identify a section. How did you model SECTION? Why did you choose this way versus alternative ways to model SECTION? e. A hospital has a large number of registered physicians. Attributes of PHYSICIAN include PhysicianJlD (the identifier) and Specialty. Patients are admitted to the hospital by physicians. Attributes of PATIENT include Patient_ID (the identifier) and Patient_Name. Any patient who is admitted must have exactly one admitting physician. A physician may optionally admit any number of patients. Once admitted, a given patient must be treated by at least one physician. A particular physician may treat any number of patients, or may not treat any patients. Whenever a patient is treated by a physician, the hospital wishes to record the details of the treatment (Treatment_Detail). Components of Treatment_Detail include Date, Time, and

Results. Did you draw more than one relationship between physician and patient? Why or why not? f. An organization makes many models of car, where a model is characterized by a name and suffix (such as GL or XL, which indicates the degree of luxury) and an engine size. Each model is made from many parts and each part may be used in the manufacturing of more than one model. Each part has a description and an ID code. Each model of car is produced at just one of the firm s Factories, which are located in Islamabad, Lahore, Faisalabad, Sahiwal and Karachi, one in each city. A factory produces many models of car and many types of parts, although each type of part is produced at one factory only.