Faculty of Engineering and Architecture. Computer Engineering Department DATABASE MANAGEMENT SYSTEMS POSTLAB #3 SOLUTION



Similar documents
Introduction to SQL ( )

A basic create statement for a simple student table would look like the following.

Sakila Sample Database

New York University Computer Science Department Courant Institute of Mathematical Sciences

Mul$media im Netz (Online Mul$media) Wintersemester 2014/15. Übung 03 (Nebenfach)

Using SQL Server Management Studio

Oracle Database 10g Express

Extracting META information from Interbase/Firebird SQL (INFORMATION_SCHEMA)

An Example: Video Rental System

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

CSI 2132 Lab 3. Outline 09/02/2012. More on SQL. Destroying and Altering Relations. Exercise: DROP TABLE ALTER TABLE SELECT

Online shopping cart. Tarik Guelzim Graduate school of computer science at Monmouth University. CS517 Database management systems Project 2

Application note: Connecting the to a Database

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

Customer Bank Account Management System Technical Specification Document

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

Database Query 1: SQL Basics

CSC 443 Data Base Management Systems. Basic SQL

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

Programming with SQL

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

A Tool for Generating Relational Database Schema from EER Diagram

Chapter 1: Introduction. Database Management System (DBMS)

DbSchema Tutorial with Introduction in SQL Databases

CPS352 Database Systems: Design Project

Databases What the Specification Says

Tutorial on Relational Database Design

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

Programming Database lectures for mathema

Physical Database Design Process. Physical Database Design Process. Major Inputs to Physical Database. Components of Physical Database Design

An Introduction to PL/SQL. Mehdi Azarmi

Using Temporary Tables to Improve Performance for SQL Data Services

In This Lecture. Security and Integrity. Database Security. DBMS Security Support. Privileges in SQL. Permissions and Privilege.

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

大 型 企 业 级 数 据 库 管 理 与 优 化. Lab Instruction

Question 1. Relational Data Model [17 marks] Question 2. SQL and Relational Algebra [31 marks]

EECS 647: Introduction to Database Systems

A Project Presentation on Online Car Rental System

SQL Tables, Keys, Views, Indexes

SQL NULL s, Constraints, Triggers

SQL Server Database Coding Standards and Guidelines

Developing Web Applications for Microsoft SQL Server Databases - What you need to know

SQL Server An Overview

CSCE 156H/RAIK 184H Assignment 4 - Project Phase III Database Design

Creating Database Tables in Microsoft SQL Server

Exercise 1: Relational Model

Database Design Process. ER Model. Goals. Relational Model. SQL - The Language of Databases. IT420: Database Management and Organization

Conventional Files versus the Database. Files versus Database. Pros and Cons of Conventional Files. Pros and Cons of Databases. Fields (continued)

Database Development and Management with SQL

Introduction to database management systems

CHAPTER 8: SQL-99: SCHEMA DEFINITION, BASIC CONSTRAINTS, AND QUERIES

Intermediate SQL C H A P T E R4. Practice Exercises. 4.1 Write the following queries in SQL:

You can use command show database; to check if bank has been created.

Tutorial: How to Use SQL Server Management Studio from Home

5. CHANGING STRUCTURE AND DATA

IENG2004 Industrial Database and Systems Design. Microsoft Access I. What is Microsoft Access? Architecture of Microsoft Access

DIPLOMA IN WEBDEVELOPMENT

Databasesystemer, forår 2005 IT Universitetet i København. Forelæsning 3: Business rules, constraints & triggers. 3. marts 2005

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

AUTHENTICATION... 2 Step 1:Set up your LDAP server... 2 Step 2: Set up your username... 4 WRITEBACK REPORT... 8 Step 1: Table structures...

Structured Query Language. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

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

Designing Databases. Introduction

SQL. Short introduction

Module 1: Getting Started with Databases and Transact-SQL in SQL Server 2008

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

IT2304: Database Systems 1 (DBS 1)

Writing Queries Using Microsoft SQL Server 2008 Transact-SQL

Web Application Development Using UML

CPSC 3375 Final Project ER Diagram

OBJECT ORIENTED EXTENSIONS TO SQL

Fundamentals of Database System

IT2305 Database Systems I (Compulsory)

SQL 2: GETTING INFORMATION INTO A DATABASE. MIS2502 Data Analytics

Relational Schema of Database:

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA

Database 2 Lecture I. Alessandro Artale

Getting Started with Telerik Data Access. Contents

constraint PKnbrVol primary key (No_vol) ); DROP TABLE segmentdevol CASCADE CONSTRAINTS; CREATE TABLE segmentdevol( numeric(9) NOT NULL,

Chapter 6: Integrity Constraints

Database Management Systems Comparative Study: Performances of Microsoft SQL Server Versus Oracle

How To Create A Table In Sql (Ahem)

Query Builder. The New JMP 12 Tool for Getting Your SQL Data Into JMP WHITE PAPER. By Eric Hill, Software Developer, JMP

A PROJECT PRESENTATION ON ONLINE MOVIE TICKET BOOKING SYSTEM. Submitted To : Department Of Computer Science

Geodatabase Programming with SQL

types, but key declarations and constraints Similar CREATE X commands for other schema ëdrop X name" deletes the created element of beer VARCHARè20è,

Database Design and Development Simplified

Database Systems. S. Adams. Dilbert. Available: Hans-Petter Halvorsen, M.Sc.

8- Management of large data volumes

Foundations of Information Management

How to Link Tables Using. SQL Named Parameters

Writing Queries Using Microsoft SQL Server 2008 Transact-SQL

14 Triggers / Embedded SQL

Database System Concepts

Database Design Patterns. Winter Lecture 24

CIS 631 Database Management Systems Sample Final Exam

Transcription:

Faculty of Engineering and Architecture Computer Engineering Department DATABASE MANAGEMENT SYSTEMS POSTLAB #3 SOLUTION

CREATING TABLES DVD Company Table create table dvd_company ( name varchar(15) not null unique, constraint pk_dvd primary key (code)); DVD Compnay Branch Table create table dvd_comp_branch ( code int, branch_id number(2), street varchar(10), state varchar(10), city varchar(10), phonenumber varchar(10), constraint pk_branch primary key (code,branch_id), constraint fk foreign key (code) references dvd_company(code) on delete cascade ); Customer Table create table customer ( customer_id number(4), name varchar(20), address varchar(10), registerdate date not null, branch_id number(2) not null, constraint pk_customer primary key (customer_id), constraint fk_comp foreign key (code,branch_id) references dvd_comp_branch(code,branch_id) on delete cascade ); DVD Table create table DVD ( catalog_number number(3), title varchar(20), category varchar(10), constraint pk_movie primary key (catalog_number)); Has Table create table HAS( branch_id number(2) not null, catalog_number number(3) not null, dvd_number int not null, status char(2), primary key (code,branch_id,catalog_number,dvd_number), foreign key (code,branch_id) references dvd_comp_branch(code,branch_id) on delete cascade, foreign key (catalog_number) references dvd(catalog_number) on delete cascade); create table RENT(

rent_id int not null, customerid number(4) not null, catalog_number number(3) not null, dvd_number int not null, rentdate date not null, primary key (rent_id), foreign key (customerid) references customer(customer_id ) on delete cascade, foreign key (catalog_number) references dvd(catalog_number) on delete cascade); ADDING RECORDS TO TABLES Adding DVD companies insert into DVD_COMPANY values(1,'gediz DVD'); insert into DVD_COMPANY values(2,'menemen DVD'); Adding DVD company branches values(1,10,'john','virginia','fairfax','9333333333'); values(1,11,'marry','virginia','tonn','9233333333'); values(2,10,'kazim','dirik','izmir','921111111'); values(2,11,'sevgi','uskudar','istanbul','911111111'); Adding customers insert into CUSTOMER values(1000,'sevgi','johnstreet',to_date('15/jan/2015'),1,10); insert into CUSTOMER values(1000,'sevgi','johnstreet',to_date('15/jan/2015'),1,10); insert into CUSTOMER values(1001,'kenan','johnstreet','13/jan/2015',1,10); insert into CUSTOMER values(1002,'sevda','marystreet',('1/jan/2014'),1,11); insert into CUSTOMER values(1003,'esra','red Street','1/Jan/2013',1,11); insert into CUSTOMER values(1004,'canan','kazmstreet','15/jan/2015',2,10); insert into CUSTOMER values(1005,'ufuk','tonstreet','13/feb/2015',2,10); insert into CUSTOMER values(1006,'yildiz','sevstreet','11/feb/2014',2,11); insert into CUSTOMER values(1007,'utku','guvstreet','13/feb/2014',2,11); Adding DVDs insert into DVD values(100,'babam ve Oglum','Drama'); insert into DVD values(101,'titanic','romantic'); insert into DVD values(102,'crazy','comedy'); Adding records to HAS tables insert into HAS values(1,10,100,1,'a'); insert into HAS values(1,10,101,1,'a'); insert into HAS values(1,10,101,2,'na'); insert into HAS values(1,10,101,3,'a'); insert into HAS values(1,11,102,1,'a'); insert into HAS values(2,10,101,1,'na'); insert into HAS values(2,10,101,2,'a');

insert into HAS values(2,10,102,1,'a'); insert into HAS values(2,11,100,1,'a'); insert into HAS values(2,11,101,1,'a'); insert into HAS values(2,11,102,1,'na'); Adding records to Rent table insert into RENT values(1,1001,101,2,'14/jan/2015'); insert into RENT values(2,1004,101,1,'16/jan/2015'); insert into RENT values(3,1007,102,1,'14/jan/2015'); QUERIES 1) Display branch id, street and phone number of all branches that locate in city whose name begins with I. select branch_id, street,phonenumber from DVD_COMP_BRANCH where city like 'I%'; 2) Find all customers who have registered to any branch after 12/JAN/2015. List the result as customer name and register date. select name,registerdate from CUSTOMER where REGISTERDATE>='13/JAN/2015'; 3) Find all Dvds are belonged to the company whose code is 2 and list the results with company name, dvd title, status and category order by dvd title. select dc.name COMPANY_NAME, d.title FILM_TITLE, h.status,d.category from DVD_COMPANY dc, DVD d, HAS h where dc.code=2 and dc.code = h.code and d.catalog_number =h.catalog_number order by d.title; 4) Find all customers that registered to company=1 and branch=11 and list the result with customer name and register date. select name,registerdate from customer,dvd_comp_branch where customer.code=1 AND customer.branch_id=11 AND customer.code=dvd_comp_branch.code AND customer.branch_id= DVD_COMP_BRANCH.BRANCH_ID; 5) Find all DVDs that are not rented in branch that locates in Fairfax and display result with dvd number, dvd title and dvd category order by dvd number select HAS.DVD_NUMBER, DVD.TITLE, DVD.CATEGORY from DVD,DVD_COMP_BRANCH,HAS where DVD_COMP_BRANCH.CITY='Fairfax' AND DVD_COMP_BRANCH.CODE = has.code AND DVD_COMP_BRANCH.BRANCH_ID = has.branch_id and DVD.CATALOG_NUMBER= has.catalog_number AND HAS.STATUS='A' order by HAS.DVD_NUMBER; 6) Find all customers who rented Titanic. Display customer name, dvd title and rent date. select customer.name,dvd.title,rent.rentdate from DVD,rent,customer where dvd.title='titanic' and dvd.catalog_number=rent.catalog_number and rent.customerid = customer.customer_id;

7) Retrieve ids and names of all customers whose ids are between 1000 and 1005. select customer.customer_id,customer.name from customer where CUSTOMER_ID between 1000 and 1005; 8) Ufuk wants to rent Crazy film in branch where he has registered. Crazy film s first copy is available for renting. So write proper SQL statement that add record to rent table and then update has table. insert into rent values(4,1005,102,1,sysdate); update has set status='na' where BRANCH_ID=10 and CODE=2 and DVD_NUMBER=1; 9) Kenan gives the rented DVD back. So delete Kenan s rental information from rent table. Then update has table. delete from rent where CUSTOMERID=1001; update has set status='a' where CATALOG_NUMBER=101 and DVD_NUMBER=2 and CODE=1 and BRANCH_ID=10; 10) Delete branch whose code is 2 and branch id is 11. delete from DVD_COMP_BRANCH where code=2 and BRANCH_ID=11;