Q1: Consider the following Company database, describing the data of customer s orders: ORDERS ( OrderNo, Month, Cid, Aid, Pid, OrderedQuantity, Cost )

Similar documents
LAB 3 Part 1 ADBC - Interactive SQL Queries-Advanced

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

Fname A variable character field up to 15 characters in length. Must have a value Lname A variable character field up to 15

EXAMINATION PAPER. Exam in: INF-2700 Database Systems Date: Thursday Time: Kl 15:00-19:00 Place: Åsgårdveien 9. Approved aids: None

Database Development (H4)

COMP 430 Intro. to Database Systems

The Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC)

SQL Data Definition Language: Create and Change the Database Ray Lockwood

MTAT Introduction to Databases

Database Applications (15-415)

CSE 344 JANUARY 5 TH INTRO TO THE RELATIONAL DATABASE

Database Systems CSE 303. Lecture 02

Database Systems CSE 303. Lecture 02

Introduction. Example Databases

Introduction The SELECT statement: basics Nested queries Set operators Update commands Table management

Lecture 04: SQL. Monday, April 2, 2007

Babu Madhav Institute of Information Technology 2015

D B M G. SQL language: basics. Managing tables. Creating a table Modifying table structure Deleting a table The data dictionary Data integrity

Chapter # 7 Introduction to Structured Query Language (SQL) Part I

SQL DDL. Intro SQL CREATE TABLE ALTER TABLE Data types Service-based database in Visual Studio Database in PHPMyAdmin

Keys, SQL, and Views CMPSCI 645

CGS 3066: Spring 2017 SQL Reference

Full file at

Introduction to Databases CSE 414. Lecture 2: Data Models

Introduction to Data Management CSE 344. Lecture 2: Data Models

Lecture 04: SQL. Wednesday, October 4, 2006

G64DBS Database Systems. Lecture 7 SQL SELECT. The Data Dictionary. Data Dictionaries. Different Sections of SQL (DDL) Different Sections of SQL (DCL)

Introduction to SQL. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011

Administrivia. The Relational Model. Review. Review. Review. Some useful terms

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Today's Party. Example Database. Faloutsos/Pavlo CMU /615

Introduction to SQL Part 1 By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford)

Principles of Database Systems CSE 544. Lecture #2 SQL The Complete Story

SQL Simple Queries. Chapter 3.1 V3.01. Napier University

Do not turn to the next page until the start of the exam.

Lecture 2: Introduction to SQL

Data, Databases, and DBMSs

Full file at

Overview of Data Management

Perceptive Content. Release Notes. Version: 7.0.x

Relational Data Structure and Concepts. Structured Query Language (Part 1) The Entity Integrity Rules. Relational Data Structure and Concepts

GlobAl EDITION. Database Concepts SEVENTH EDITION. David M. Kroenke David J. Auer

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

SQL DATA DEFINITION LANGUAGE

Database Management Systems,

TUTORIAL FOR IMPORTING OTTAWA FIRE HYDRANT PARKING VIOLATION DATA INTO MYSQL

SQL DATA DEFINITION LANGUAGE

DS Introduction to SQL Part 1 Single-Table Queries. By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford)

1. Data Model, Categories, Schemas and Instances. Outline

The Relational Model. Suan Lee

2) SQL includes a data definition language, a data manipulation language, and SQL/Persistent stored modules. Answer: TRUE Diff: 2 Page Ref: 36

CMPT 354: Database System I. Lecture 2. Relational Model

Chapter-14 SQL COMMANDS

The Relational Model

SQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p:// Lecture 3

The Relational Model

Programming Logic and Design Sixth Edition

Database Systems CSE 414

CSE 344 JANUARY 8 TH SQLITE AND JOINS

CS2 Current Technologies Lecture 2: SQL Programming Basics

UNIVERSITY OF BOLTON WESTERN INTERNATIONAL COLLEGE FZE BSC (HONS) COMPUTING SEMESTER ONE EXAMINATION 2015/2016 DATABASE THEORY AND PRACTICE

5 Years Integrated M.Sc.(IT) Semester 1 Practical LIST CC2 Database Management Systems

Midterm Review. Winter Lecture 13

A Beginner s Guide to Programming Logic, Introductory. Chapter 6 Arrays

IELM 511 Information Systems Design Labs 5 and 6. DB creation and Population

Industry Models. Physical Model Guidelines. Industry Models - Physical Model Guidelines. Industry Models - Physical Model Guidelines November 21, 2013

CS 4400 Introduction to Database Systems 2002 Spring Term Project (Section A)

The Relational Model of Data (ii)

TUTORIAL FOR IMPORTING OTTAWA FIRE HYDRANT PARKING VIOLATION DATA INTO MYSQL

Perceptive Content. Release Notes. Version: 7.0.x

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

King Fahd University of Petroleum and Minerals

Announcements. Using Electronics in Class. Review. Staff Instructor: Alvin Cheung Office hour on Wednesdays, 1-2pm. Class Overview

Midterm 1: CS186, Spring I. Storage: Disk, Files, Buffers [11 points] cs186-

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language

CS143: Relational Model

Introduction to Data Management CSE 344

Homework 5: Miscellanea (due April 26 th, 2013, 9:05am, in class hard-copy please)

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

SQL DATA DEFINITION LANGUAGE

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

Chapter 1 SQL and Data

Lecture 3: SQL Part II

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

Test Bank for Database Processing Fundamentals Design and Implementation 13th Edition by Kroenke

SQL - Subqueries and. Schema. Chapter 3.4 V4.0. Napier University

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

ADF Desktop Integration 11g Release1 Component and Feature Demo

Announcements. PS 3 is out (see the usual place on the course web) Be sure to read my notes carefully Also read. Take a break around 10:15am

COMP 430 Intro. to Database Systems

INDIAN SCHOOL MUSCAT FIRST PRELIMINARY EXAMINATION 2017 INFORMATICS PRACTICES

Big Data Processing Technologies. Chentao Wu Associate Professor Dept. of Computer Science and Engineering

DB Fundamentals Exam.

Database Systems CSE 414

Database Management Systems

Lab # 3 Hands-On. DML Basic SQL Statements Institute of Computer Science, University of Tartu, Estonia

Midterm Exam #2 (Version B) CS 122A Spring 2018

Locate your Advanced Tools and Applications

DATABASE MANAGEMENT SYSTEMS. UNIT I Introduction to Database Systems

Chapter 3: Introduction to SQL

Transcription:

King Saud University College of Computer and Information Sciences Department of Information Technology CAP261/IT222 Database Principles Assignment #4 Second Semester 1431/1432 H SQL - DML Q1: Consider the following Company database, describing the data of customer s orders: CUSTOMER ( Cid, CName, City, Discount ) AGENT ( Aid, AName, City, Percent ) PRODUCT ( Pid, PName, City, Quantity, Price ) ORDERS ( OrderNo, Month, Cid, Aid, Pid, OrderedQuantity, Cost ) Write the appropriate SQL statements that perform the following queries: ( Solve part 10, 11 and 12, only when you finished all the previous queries to avoid changing the data. ) Important note: You must change the name of any manipulated column. 1) List the names of agents that placed an order for customer C003 or customer C006. 2) List all pair of products names that are in the same city, along with their city name. 3) List the number of orders and their total cost for each agent that handled orders with more than $1,000 in total; showing the agent name. 4) List the names of all customers and the total cost of their orders if they have placed an order. 5) List the id and the name of products that were not ordered through agents A04. 6) List the id of products ordered by any agent who makes at least one order for a customer in Kyoto. 7) List the id and discount percentage of customers who have the largest discount and those who have the smallest discount. 8) List the id and name of agents with name beginning with the letter J or B and who do not place orders for a Product located in Dallas.

9) List name of customers that ordered all the products. 10) Insert a new order for the customer that didn t have any orders; with 1030 as order number which has been placed in November by agent number A01 for product number P06 with quantity of 90. Note: unknown values have to be selected from existing data. 11) Decrease by 10% the price of all products located in Dallas. 12) Delete all orders placed by agents living in New York city. Instructions: This assignment should be solved using OracleXE DBMS (Database home page SQL worksheet). Your solution should include the input (query) as well as the output (result). If you solve assignment without oracle DBMS you will get 0 as your mark. Make sure to execute script in figure1 before executing the queries. The script in figure1 will create the DB schema for you and will also populate the tables with mock data. To create the DB in your account, login to OracleXE DB Home Page, then copy and paste the script shown in figure1 into your SQL interface and execute them. The first time that you run the script, you will probably see some error messages indicating that the drop table statements failed. You may ignore these messages. Note: In OracleXE you need to execute each statement (which ends with ; ) separately. What to Turn In: In one MS word document, show the following for each question: The Question Number and the Question Text. The SQL query answer (input query). The resulted output. i.e. after executing your SQL query in the worksheet, select the resulted table in the lower panel (output panel) of the worksheet window, then copy and paste it into your Word Document. Don t change the resulted table format. For the last 3 questions, just copy and paste the resulted statements. Note: Figure2 shows the relations with its data that have been created in your account after executing Figure1 script. You can check the correctness of the resulted table of your query by checking these tables.

Figure 1: Company Database DDL statements. drop table customer; create table customer ( Cid char(4), CName varchar(13), Discount real, constraint custpk primary key (Cid)); drop table agent; create table agent ( Aid AName varchar(13), Percent number(6), constraint agtpk primary key (Aid)); drop table product; create table product ( Pid PName varchar(13), Quantity number(10), Price real, constraint prdpk primary key (Pid)); drop table orders; create table orders ( OrderNo number(6), Month char(8), Cid char(4), Aid Pid OrderedQuantity number(6), Cost float, constraint ordpk primary key (OrderNo)); insert into customer values('c001','tiptop','duluth',10.00); insert into customer values('c002','basics','dallas',12.00); insert into customer values('c003','allied','dallas',8.00); insert into customer values('c004','acme1','duluth',8.00); insert into customer values('c005','top1','duluth',0.00); insert into customer values('c006','acme2','kyoto',0.00);

insert into product values('p01','comb','dallas',111400,0.5); insert into product values('p02','brush','newark',203000,0.5); insert into product values('p03','razor','duluth',150600,1.00); insert into product values('p04','pen','duluth',125300,1.00); insert into product values('p05','pencil','dallas',221400,1.00); insert into product values('p06','folder','dallas',123100,2.00); insert into product values('p07','case','newark',100500,1.00); insert into agent values('a01','smitho','new York',6); insert into agent values('a02','jones','newark',6); insert into agent values('a03','brown','tokyo',7); insert into agent values('a04','gray','new York',6); insert into agent values('a05','otasi','duluth',5); insert into agent values('a06','smiths','dallas',5); insert into orders values(1011,'january','c001','a01','p01',1000,450.00); insert into orders values(1012,'january','c001','a01','p01',1000,450.00); insert into orders values(1019,'february','c001','a02','p02',400,180.00); insert into orders values(1017,'february','c001','a06','p03',600,540.00); insert into orders values(1018,'february','c001','a03','p04',600,540.00); insert into orders values(1023,'march','c001','a04','p05',500,450.00); insert into orders values(1022,'march','c001','a05','p06',400,720.00); insert into orders values(1025,'april','c001','a05','p07',800,720.00); insert into orders values(1013,'january','c002','a03','p03',1000,880.00); insert into orders values(1026,'may','c002','a05','p03',800,704.00); insert into orders values(1015,'january','c003','a03','p05',1200,1104.00); insert into orders values(1014,'january','c003','a03','p05',1200,1104.00); insert into orders values(1021,'february','c004','a06','p01',1000,460.00); insert into orders values(1016,'january','c006','a01','p01',1000,500.00); insert into orders values(1020,'february','c006','a03','p07',600,600.00); insert into orders values(1024,'march','c006','a06','p01',800,400.00);

Figure 2: Company Database relations. Customer Agent CID CNAME CITY DISCOUNT AID ANAME CITY PERCENT C001 Tiptop Duluth 10 A01 SmithO New York 6 C002 Basics Dallas 12 A02 Jones Newark 6 C003 Allied Dallas 8 A03 Brown Tokyo 7 C004 ACME1 Duluth 8 A04 Gray New York 6 C005 Top1 Duluth 0 A05 Otasi Duluth 5 C006 ACME2 Kyoto 0 A06 SmithS Dallas 5 Product PID PNAME CITY QUANTITY PRICE P01 Comb Dallas 111400.5 P02 Brush Newark 203000.5 P03 Razor Duluth 150600 1 P04 Pen Duluth 125300 1 P05 Pencil Dallas 221400 1 P06 Folder Dallas 123100 2 P07 Case Newark 100500 1 Orders ORDERNO MONTH CID AID PID ORDEREDQUANTITY COST 1011 January C001 A01 P01 1000 450 1012 January C001 A01 P01 1000 450 1019 February C001 A02 P02 400 180 1017 February C001 A06 P03 600 540 1018 February C001 A03 P04 600 540 1023 March C001 A04 P05 500 450 1022 March C001 A05 P06 400 720 1025 April C001 A05 P07 800 720 1013 January C002 A03 P03 1000 880 1026 May C002 A05 P03 800 704 1015 January C003 A03 P05 1200 1104 1014 January C003 A03 P05 1200 1104 1021 February C004 A06 P01 1000 460 1016 January C006 A01 P01 1000 500 1020 February C006 A03 P07 600 600 1024 March C006 A06 P01 800 400