Assignment #2. CS Spring 2015 Due on Friday, June 19, 2015, 9 AM For instructions on how to submit your assignment check the course website.

Size: px
Start display at page:

Download "Assignment #2. CS Spring 2015 Due on Friday, June 19, 2015, 9 AM For instructions on how to submit your assignment check the course website."

Transcription

1 Assignment #2 CS Spring 2015 Due on Friday, June 19, 2015, 9 AM For instructions on how to submit your assignment check the course website. 1

2 CS Spring 2015 : Assignment #2 QUESTION 1. Question 1. Consider the following database schema: Emp(eid : integer, ename : string, age : integer, salary : real) W orks(eid : integer, did : integer, pct time : integer) Dept(did : integer, budget : real, managerid : integer) Write SQL statements to answer the tasks that follow: 1. Create the Emp table. CREATE TABLE emp ( eid INTEGER PRIMARY KEY, ename VARCHAR(20), age INTEGER, salary DECIMAL(8, 2) ); 2. Insert the following instance into Emp. Emp eid ename age salary 1 Donald Duck 35 18, Minnie Mouse 19 9, Mickey Mouse 24 20, Goof y 20 13, 000 INSERT INTO emp VALUES (1, Donald Duck, 35, 18000), (4, Minnie Mouse, 19, 9000 ), (2, Mickey Mouse, 24, ), (3, Goofy, 20, ); Page 2 of 11

3 CS Spring 2015 : Assignment #2 QUESTION Try altering the Emp table to define a constraint that will ensure that every employee makes at least $10,000. ALTER TABLE emp ADD CONSTRAINT check_salary CHECK (salary > 10000); 4. Give Minnie a salary increase of $2,000. UPDATE emp SET salary = salary WHERE ename LIKE %Minnie% ; 5. Alter the Emp table to define a constraint that will ensure that every employee makes at least $10,000. ALTER TABLE emp ADD CONSTRAINT check_salary CHECK (salary > 10000); 6. Create the Dept table. CREATE TABLE dept ( did INTEGER PRIMARY KEY, budget DECIMAL(9, 2), managerid INTEGER ); 7. Alter the Dept table to define a foreign key constraint (with cascade delete) on managerid, referencing Emp table. ALTER TABLE dept ADD CONSTRAINT manager_fk FOREIGN KEY (managerid) REFERENCES emp (eid) ON DELETE CASCADE; 8. Insert a valid tuple in Dept. INSERT INTO dept VALUES (1, , 1); 9. Delete all tuples from Emp. DELETE FROM emp; Page 3 of 11

4 CS Spring 2015 : Assignment #2 QUESTION List all tuples from Dept. SELECT * FROM dept; 11. Create the W orks table and define foreign key constraints on eid and did, referencing Emp and Dept tables, respectively. CREATE TABLE works ( eid INTEGER REFERENCES emp ON DELETE CASCADE, did INTEGER REFERENCES dept ON DELETE CASCADE, pct_time INTEGER, PRIMARY KEY (eid, did) ); 12. Populate all 3 relations with 3 to 6 valid tuples. INSERT INTO emp VALUES (1, Donald Duck, 35, 18000), (4, Minnie Mouse, 19, ), (2, Mickey Mouse, 24, ), (3, Goofy, 20, ); INSERT INTO dept VALUES (100, , 1), (200, , 1), (300, , 3); INSERT INTO works VALUES (1, Page 4 of 11

5 CS Spring 2015 : Assignment #2 QUESTION , 310), (1, 200, 120), (4, 300, 410), (3, 300, 180), (2, 200, 190); 13. Delete all information about employees whose salaries exceed that of the manager of one or more departments that they work in. Ensure that all the relevant integrity constraints are satisfied after your updates. DELETE FROM emp E WHERE E.eid IN (SELECT W.eid FROM works W, emp M, dept D WHERE W.did = D.did AND D.managerid = M.eid AND E.salary > M.salary); Page 5 of 11

6 Question 2. Consider the following database schema: P roduct(manufacturer, Model, T ype) Computer(M odel, Speed, RAM, HD, CD, Screen, P rice) P rinter(model, Color, T ype, P rice) and its instance: P roduct M anuf acturer M odel T ype A 1001 pc A 1002 pc A 1003 pc B 1004 pc B 1006 pc B 3002 printer B 3004 printer C 1005 pc C 1007 pc D 1008 pc D 1009 pc D 1010 pc D 2001 laptop D 2002 laptop D 2003 laptop D 3001 printer D 3003 printer E 2004 laptop E 2008 laptop F 2005 laptop G 2006 laptop G 2007 laptop H 3005 printer I 3006 printer Computer M odel Speed RAM HD CD Screen P rice x x x x x x x x x x x x x x x x x x P rinter Model Color T ype P rice 3001 true ink jet true ink jet f alse laser true laser f alse ink jet true dry 129 Page 6 of 11

7 Write SQL queries to answer the following: 1. Which laptop models are shown in the P roduct relation? SELECT DISTINCT model WHERE model IS NOT NULL AND type = laptop ; 2. Find the set of all manufacturers ordered alphabetically. SELECT DISTINCT manufacturer WHERE manufacturer IS NOT NULL ORDER BY manufacturer ASC ; 3. Which computer models appear in the database? SELECT DISTINCT model FROM computer WHERE model IS NOT NULL; 4. Which computer models use 256 MB of RAM? SELECT DISTINCT model FROM computer WHERE ram = 256 AND model IS NOT NULL; 5. Which computer models cost less than $1100? SELECT DISTINCT model FROM computer WHERE price < 1100 AND model IS NOT NULL; 6. Which laptop models have a HD of at least 50 GB and cost less than $1400? SELECT DISTINCT p.model p, computer c WHERE p.model = c.model AND p.type = laptop AND c.hd >= 50 AND c.price < 1400; Page 7 of 11

8 7. Which laser printer models can print color documents? SELECT DISTINCT model FROM printer WHERE color = true AND type = laser AND model IS NOT NULL; 8. Which laptop models that have more than 256 MB of RAM are produced by manufacturer D? SELECT DISTINCT p.model p, computer c WHERE p.model = c.model AND p.type = laptop AND p.manufacturer = D AND c.ram > 256; 9. Which computer models that have more than 256 MB of RAM are produced by manufacturer D? SELECT DISTINCT p.model p, computer c WHERE p.model = c.model AND p.manufacturer = D AND c.ram > 256; 10. Which laptop models cost less than $1200? SELECT DISTINCT p.model p, computer c WHERE p.model = c.model AND p.type = laptop AND c.price < 1200; 11. Which manufacturers produce personal computers and printers? SELECT DISTINCT p1.manufacturer p1, product p2 WHERE p1.manufacturer = p2.manufacturer AND p1.type = pc AND p2.type = printer ; 12. Which manufacturers produce all the product types? Page 8 of 11

9 SELECT DISTINCT manufacturer WHERE manufacturer IS NOT NULL GROUP BY manufacturer HAVING Count(DISTINCT type) >= ALL (SELECT Count(DISTINCT type) ); 13. Which manufacturers supply only personal computers? WHERE type = pc AND manufacturer IS NOT NULL EXCEPT WHERE type <> pc ; 14. Which manufacturers supply only one type of product? WHERE manufacturer IS NOT NULL GROUP BY manufacturer HAVING Count(DISTINCT type) = 1; 15. You want to buy: a personal computer with at least 1024 MB of RAM and a CD with 56x, and a laptop with a screen larger than 15, and a printer cheaper than $300 all produced by the same manufacturer. Which manufacturers should you consider? SELECT DISTINCT pc.manufacturer FROM (product natural JOIN computer) AS pc, (product natural JOIN computer ) AS l, (product JOIN printer ON product.model = printer.model) AS pr WHERE pc.manufacturer = l.manufacturer AND pc.manufacturer = pr.manufacturer AND pc.type = pc AND pc.ram >= 1024 AND pc.cd = 56x Page 9 of 11

10 AND l.type = laptop AND l.screen > 15 AND pr.price < 300; 16. What HD sizes are common to at least 2 computers? SELECT hd FROM computer GROUP BY hd HAVING Count(DISTINCT model) >= 2; 17. Which manufacturers sell more than one computer that has a processor speed of less than 3 GHz? natural JOIN computer WHERE speed <= 3 AND manufacturer IS NOT NULL GROUP BY manufacturer HAVING Count(DISTINCT model) > 1; 18. Which manufacturers sell the fastest computers? SELECT DISTINCT manufacturer natural JOIN computer WHERE speed = (SELECT Max(speed) FROM computer) AND manufacturer IS NOT NULL; 19. Which manufacturers do not sell laptops? SELECT DISTINCT manufacturer WHERE manufacturer NOT IN ( WHERE type = laptop ); 20. Which manufacturers offer at least 2 laptop models? WHERE type = laptop AND manufacturer IS NOT NULL GROUP BY manufacturer HAVING Count(DISTINCT model) >= 2; Page 10 of 11

11 21. Which manufacturers offer exactly 3 types of personal computers? WHERE type = pc AND manufacturer IS NOT NULL GROUP BY manufacturer HAVING Count(DISTINCT model) = 3; 22. You need to buy: a computer that has at least 1024 MB of RAM, a processor speed of 3 GHz or 3.5 GHz, a HD of at least 160 GB, and a color printer. Which manufacturers can offer you this combination and at what total price? SELECT DISTINCT p1.manufacturer, c.price + i.price AS total_price FROM computer AS c, product AS p1, printer AS i, product AS p2 WHERE p1.manufacturer = p2.manufacturer AND c.model = p1.model AND c.ram >= 1024 AND c.hd >= 160 AND ( c.speed = 3 OR c.speed = 3.5 ) AND i.model = p2.model AND i.color = true; Page 11 of 11

University of Massachusetts Amherst Department of Computer Science Prof. Yanlei Diao

University of Massachusetts Amherst Department of Computer Science Prof. Yanlei Diao University of Massachusetts Amherst Department of Computer Science Prof. Yanlei Diao CMPSCI 445 Midterm Practice Questions NAME: LOGIN: Write all of your answers directly on this paper. Be sure to clearly

More information

COMP7640 Assignment 2

COMP7640 Assignment 2 COMP7640 Assignment 2 Due Date: 23:59, 14 November 2014 (Fri) Description Question 1 (20 marks) Consider the following relational schema. An employee can work in more than one department; the pct time

More information

DATABASE MANAGEMENT SYSTEMS

DATABASE MANAGEMENT SYSTEMS www..com Code No: N0321/R07 Set No. 1 1. a) What is a Superkey? With an example, describe the difference between a candidate key and the primary key for a given relation? b) With an example, briefly describe

More information

Integrity constraints, relationships. CS634 Lecture 2

Integrity constraints, relationships. CS634 Lecture 2 Integrity constraints, relationships CS634 Lecture 2 Foreign Keys Defined in Sec. 3.2.2 without mentioning nulls. Nulls covered in Sec. 5.6 First example: nice not-null foreign key column: create table

More information

Outer Join, More on SQL Constraints

Outer Join, More on SQL Constraints Outer Join, More on SQL Constraints CS430/630 Lecture 10 Slides based on Database Management Systems 3 rd ed, Ramakrishnan and Gehrke Outer Joins Include in join result non-matching tuples Result tuple

More information

Example Examination. Allocated Time: 100 minutes Maximum Points: 250

Example Examination. Allocated Time: 100 minutes Maximum Points: 250 CS542 EXAMPLE EXAM Elke A. Rundensteiner Example Examination Allocated Time: 100 minutes Maximum Points: 250 STUDENT NAME: General Instructions: This test is a closed book exam (besides one cheat sheet).

More information

CSC 370 Database Systems Summer 2004 Solutions for Exercise No. 1 Version 1.0 June 14, 2004

CSC 370 Database Systems Summer 2004 Solutions for Exercise No. 1 Version 1.0 June 14, 2004 Problem 4.2 CSC 370 Database Systems Summer 2004 Solutions for Exercise No. 1 Version 1.0 June 14, 2004 Expression Assumption Min Max R1 R2 R1 and R2 are union compatible N2 N1 + N2 R1 R2 R1 and R2 are

More information

Translating an ER Diagram to a Relational Schema

Translating an ER Diagram to a Relational Schema Translating an ER Diagram to a Relational Schema CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 1 Translate each entity set into a table, with keys. Entity set: represented

More information

Homework 1: Relational Algebra and SQL (due February 10 th, 2016, 4:00pm, in class hard-copy please)

Homework 1: Relational Algebra and SQL (due February 10 th, 2016, 4:00pm, in class hard-copy please) Virginia Tech. Computer Science CS 4604 Introduction to DBMS Spring 2016, Prakash Homework 1: Relational Algebra and SQL (due February 10 th, 2016, 4:00pm, in class hard-copy please) Reminders: a. Out

More information

SQL Structured Query Language Introduction

SQL Structured Query Language Introduction SQL Structured Query Language Introduction Rifat Shahriyar Dept of CSE, BUET Tables In relational database systems data are represented using tables (relations). A query issued against the database also

More information

CS2300: File Structures and Introduction to Database Systems

CS2300: File Structures and Introduction to Database Systems CS2300: File Structures and Introduction to Database Systems Lecture 14: SQL Doug McGeehan From Theory to Practice The Entity-Relationship Model: a convenient way of representing the world. The Relational

More information

Database Systems CSE 303. Outline. Lecture 06: SQL. What is Sub-query? Sub-query in WHERE clause Subquery

Database Systems CSE 303. Outline. Lecture 06: SQL. What is Sub-query? Sub-query in WHERE clause Subquery Database Systems CSE 303 Lecture 06: SQL 2016 Subquery Outline What is a Subquery Subquery in WHERE clause >ALL, >ANY, >=ALL,

More information

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity COSC 416 NoSQL Databases Relational Model (Review) Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Relational Model History The relational model was proposed by E. F. Codd

More information

192 Chapter 14. TotalCost=3 (1, , 000) = 6, 000

192 Chapter 14. TotalCost=3 (1, , 000) = 6, 000 192 Chapter 14 5. SORT-MERGE: With 52 buffer pages we have B> M so we can use the mergeon-the-fly refinement which costs 3 (M + N). TotalCost=3 (1, 000 + 1, 000) = 6, 000 HASH JOIN: Now both relations

More information

QUIZ 1 REVIEW SESSION DATABASE MANAGEMENT SYSTEMS

QUIZ 1 REVIEW SESSION DATABASE MANAGEMENT SYSTEMS QUIZ 1 REVIEW SESSION DATABASE MANAGEMENT SYSTEMS SCHEMA DESIGN & RELATIONAL ALGEBRA A database schema is the skeleton structure that represents the logical view of the entire database Logical design of

More information

SQL. Char (30) can store ram, ramji007 or 80- b

SQL. Char (30) can store ram, ramji007 or 80- b SQL In Relational database Model all the information is stored on Tables, these tables are divided into rows and columns. A collection on related tables are called DATABASE. A named table in a database

More information

High-Level Database Models (ii)

High-Level Database Models (ii) ICS 321 Spring 2011 High-Level Database Models (ii) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 1 Logical DB Design: ER to Relational Entity sets to

More information

Babu Banarasi Das National Institute of Technology and Management

Babu Banarasi Das National Institute of Technology and Management Babu Banarasi Das National Institute of Technology and Management Department of Computer Applications Question Bank (Short-to-Medium-Answer Type Questions) Masters of Computer Applications (MCA) NEW Syllabus

More information

Assignment #3. CS Spring 2015 Due on Saturday, July 25, 2015, 9 AM For instructions on how to submit your assignment check the course website.

Assignment #3. CS Spring 2015 Due on Saturday, July 25, 2015, 9 AM For instructions on how to submit your assignment check the course website. Assignment #3 CS 348 - Spring 2015 Due on Saturday, July 25, 2015, 9 AM For instructions on how to submit your assignment check the course website. 1 CS 348 - Spring 2015 : Assignment #3 QUESTION 1. Question

More information

CS419 Spring Computer Security. Vinod Ganapathy Lecture 15. Chapter 5: Database security

CS419 Spring Computer Security. Vinod Ganapathy Lecture 15. Chapter 5: Database security CS419 Spring 2010 Computer Security Vinod Ganapathy Lecture 15 Chapter 5: Database security Database Security Relational Databases constructed from tables of data each column holds a particular type of

More information

SQL. A Short Note. November 14, where the part appears between [ and ] are optional. A (simple) description of components are given below:

SQL. A Short Note. November 14, where the part appears between [ and ] are optional. A (simple) description of components are given below: SQL A Short Note November 14, 2002 1 Syntax SQL Queries have the generic form as follows: SELECT [DISTINCT] List_of_attributes FROM List_of_tables [ WHERE Condition] [ ORDER BY List_Of_Ordering_Attributes

More information

CMPT 354 Database Systems. Simon Fraser University Fall Instructor: Oliver Schulte

CMPT 354 Database Systems. Simon Fraser University Fall Instructor: Oliver Schulte Assignment 2: Relational Queries, SQL. CMPT 354 Database Systems Simon Fraser University Fall 2016 Instructor: Oliver Schulte Instructions: Check the instructions in the syllabus. The university policy

More information

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints SQL KEREM GURBEY WHAT IS SQL Database query language, which can also: Define structure of data Modify data Specify security constraints DATA DEFINITION Data-definition language (DDL) provides commands

More information

Database Management Systems (COP 5725) Homework 3

Database Management Systems (COP 5725) Homework 3 Database Management Systems (COP 5725) Homework 3 Instructor: Dr. Daisy Zhe Wang TAs: Yang Chen, Kun Li, Yang Peng yang, kli, ypeng@cise.uf l.edu November 26, 2013 Name: UFID: Email Address: Pledge(Must

More information

CS 327E Lecture 2. Shirley Cohen. January 27, 2016

CS 327E Lecture 2. Shirley Cohen. January 27, 2016 CS 327E Lecture 2 Shirley Cohen January 27, 2016 Agenda Announcements Homework for today Reading Quiz Concept Questions Homework for next time Announcements Lecture slides and notes will be posted on the

More information

CSC 261/461 Database Systems Lecture 10

CSC 261/461 Database Systems Lecture 10 CSC 261/461 Database Systems Lecture 10 Spring 2018 Please put away all electronic devices Announcements From now on, no electronic devices allowed during lecture Includes Phone and Laptop Why? For your

More information

Endterm Exam (Version B) CS 122A Spring 2017

Endterm Exam (Version B) CS 122A Spring 2017 NAME: SOLUTION SEAT NO.: STUDENT ID: Endterm Exam (Version B) CS 122A Spring 2017 Max. Points: 100 (Please read the instructions carefully) Instructions: - The total time for the exam is 120 minutes; be

More information

CS W Introduction to Databases Spring Computer Science Department Columbia University

CS W Introduction to Databases Spring Computer Science Department Columbia University CS W4111.001 Introduction to Databases Spring 2018 Computer Science Department Columbia University 1 in SQL 1. Key constraints (PRIMARY KEY and UNIQUE) 2. Referential integrity constraints (FOREIGN KEY

More information

CSE 344 Midterm Nov 1st, 2017, 1:30-2:20

CSE 344 Midterm Nov 1st, 2017, 1:30-2:20 1 SQL 1. (36 points) Acompanymaintainsadatabaseabouttheiremployeesandprojectswiththefollowing schema. Employee(eid, name, salary) Project(pid, title, budget) WorksOn(eid, pid, year) WorksOn records which

More information

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

Data Modelling and Databases. Exercise Session 7: Integrity Constraints Data Modelling and Databases Exercise Session 7: Integrity Constraints 1 Database Design Textual Description Complete Design ER Diagram Relational Schema Conceptual Modeling Logical Modeling Physical Modeling

More information

Sample Question Paper

Sample Question Paper Sample Question Paper Marks : 70 Time:3 Hour Q.1) Attempt any FIVE of the following. a) List any four applications of DBMS. b) State the four database users. c) Define normalization. Enlist its type. d)

More information

Designing Tables for an Oracle Database System. From theory to practice

Designing Tables for an Oracle Database System. From theory to practice Designing Tables for an Oracle Database System Database Course, Fall 2004 From theory to practice The Entity- Relationship model: a convenient way of representing the world. The Relational model: a model

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2016 CS 348 (Intro to DB Mgmt) SQL

More information

CSE 544: Principles of Database Systems

CSE 544: Principles of Database Systems CSE 544: Principles of Database Systems Semijoin Reductions Theory Wrap-up CSE544 - Spring, 2012 1 Announcements Makeup lectures: Friday, May 18, 10:30-11:50, CSE 405 Friday, May 25, 10:30-11:50, CSE 405

More information

QUERY OPTIMIZATION [CH 15]

QUERY OPTIMIZATION [CH 15] Spring 2017 QUERY OPTIMIZATION [CH 15] 4/12/17 CS 564: Database Management Systems; (c) Jignesh M. Patel, 2013 1 Example SELECT distinct ename FROM Emp E, Dept D WHERE E.did = D.did and D.dname = Toy EMP

More information

DR B.R.AMBEDKAR UNIVERSITY B.Sc.(Computer Science): III Year THEORY PAPER IV (Elective 4) PHP, MySQL and Apache

DR B.R.AMBEDKAR UNIVERSITY B.Sc.(Computer Science): III Year THEORY PAPER IV (Elective 4) PHP, MySQL and Apache DR B.R.AMBEDKAR UNIVERSITY B.Sc.(Computer Science): III Year THEORY PAPER IV (Elective 4) PHP, MySQL and Apache 90 hrs (3 hrs/ week) Unit-1 : Installing and Configuring MySQL, Apache and PHP 20 hrs Installing

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2012 CS 348 (Intro to DB

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2012 CS 348 (Intro to DB

More information

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad Course Name Course Code Class Branch INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 04 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK : DATABASE MANAGEMENT SYSTEMS

More information

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of The SQL Query Language Data Definition Basic Query

More information

doc. RNDr. Tomáš Skopal, Ph.D. RNDr. Michal Kopecký, Ph.D.

doc. RNDr. Tomáš Skopal, Ph.D. RNDr. Michal Kopecký, Ph.D. course: Database Systems (NDBI025) SS2017/18 doc. RNDr. Tomáš Skopal, Ph.D. RNDr. Michal Kopecký, Ph.D. Department of Software Engineering, Faculty of Mathematics and Physics, Charles University in Prague

More information

NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E)

NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E) 1 NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE More Complex SQL Retrieval Queries Self-Joins Renaming Attributes and Results Grouping, Aggregation, and Group Filtering

More information

EXAMINATIONS 2009 END-YEAR. COMP302 / SWEN304 Database Systems / Database System Engineering. Appendix

EXAMINATIONS 2009 END-YEAR. COMP302 / SWEN304 Database Systems / Database System Engineering. Appendix EXAMINATIONS 2009 END-YEAR COMP302 / SWEN304 Database Systems / Database System Engineering Appendix Do not hand this Appendix in. Do not write your answers on this Appendix. Contents: Appendix A. COMPANY

More information

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas SQL SQL Functionality stands for Structured Query Language sometimes pronounced sequel a very-high-level (declarative) language user specifies what is wanted, not how to find it number of standards original

More information

ASSIGNMENT NO 2. Objectives: To understand and demonstrate DDL statements on various SQL objects

ASSIGNMENT NO 2. Objectives: To understand and demonstrate DDL statements on various SQL objects ASSIGNMENT NO 2 Title: Design and Develop SQL DDL statements which demonstrate the use of SQL objects such as Table, View, Index, Sequence, Synonym Objectives: To understand and demonstrate DDL statements

More information

Tables From Existing Tables

Tables From Existing Tables Creating Tables From Existing Tables After completing this module, you will be able to: Create a clone of an existing table. Create a new table from many tables using a SQL SELECT. Define your own table

More information

High Level Database Models

High Level Database Models ICS 321 Fall 2011 High Level Database Models Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 9/21/2011 Lipyeow Lim -- University of Hawaii at Manoa 1 Database

More information

Assignment 3: SQL SELECT Queries

Assignment 3: SQL SELECT Queries Assignment 3: SQL SELECT Queries Install MySQL on your computer ("sudo apt-get install mysql-server" on Ubuntu Linux / or follow instructions for your o/s installs). Put the following lines in ~/.my.cnf

More information

Database Management Systems

Database Management Systems Sample Questions 1 Write SQL query to create a table for describing a book. The table should have Book Title, Author, Publisher, Year published, and ISBN fields. Your table should have a primary key. For

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Winter 2017 CS 348 (Intro to DB Mgmt) SQL

More information

Information Systems. Database System Architecture. Relational Databases. Nikolaj Popov

Information Systems. Database System Architecture. Relational Databases. Nikolaj Popov Information Systems Database System Architecture. Relational Databases Nikolaj Popov Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria popov@risc.uni-linz.ac.at Outline

More information

The Entity-Relationship Model

The Entity-Relationship Model The Entity-Relationship Model Chapter 2 Instructor: Vladimir Zadorozhny vladimir@sis.pitt.edu Information Science Program School of Information Sciences, University of Pittsburgh 1 Database: a Set of Relations

More information

SQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 3

SQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 3 B0B36DBS, BD6B36DBS: Database Systems h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 3 SQL: Data De ni on Mar n Svoboda mar n.svoboda@fel.cvut.cz 13. 3. 2018 Czech Technical University

More information

CS 338 Basic SQL Part II

CS 338 Basic SQL Part II CS 338 Basic SQL Part II Bojana Bislimovska Spring 2017 Major research Outline Basic Retrieval Queries Exercises Ambiguous Attribute Names Major research Same name can be used for two or more attributes

More information

Introduction to Data Management. Lecture #10 (Relational Calculus, Continued)

Introduction to Data Management. Lecture #10 (Relational Calculus, Continued) Introduction to Data Management Lecture #10 (Relational Calculus, Continued) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v

More information

NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E)

NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E) 1 NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE More Complex SQL Retrieval Queries Self-Joins Renaming Attributes and Results Grouping, Aggregation, and Group Filtering

More information

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

The Relational Model. Why Study the Relational Model? Relational Database: Definitions The Relational Model Database Management Systems, R. Ramakrishnan and J. Gehrke 1 Why Study the Relational Model? Most widely used model. Vendors: IBM, Microsoft, Oracle, Sybase, etc. Legacy systems in

More information

CSE 344 Midterm. Wednesday, Nov. 1st, 2017, 1:30-2:20. Question Points Score Total: 100

CSE 344 Midterm. Wednesday, Nov. 1st, 2017, 1:30-2:20. Question Points Score Total: 100 CSE 344 Midterm Wednesday, Nov. 1st, 2017, 1:30-2:20 Name: Question Points Score 1 36 2 29 3 15 4 20 Total: 100 This exam is CLOSED book and CLOSED devices. You are allowed ONE letter-size page with notes

More information

CS 338: Computer Applications in Business: Databases

CS 338: Computer Applications in Business: Databases CS 338: Computer Applications in Business: Databases Spring 207 Midterm Exam Section 00 June 9, 207 0:00am :5am. There are 0 pages in this booklet, including this cover page. Please make sure that you

More information

Note that it works well to answer questions on computer instead of on the board.

Note that it works well to answer questions on computer instead of on the board. 1) SELECT pname FROM Proj WHERE budget > 250000; 2) SELECT eno FROM Emp where salary < 30000; 3) SELECT DISTINCT resp from WorksOn; 4) SELECT ename FROM Emp WHERE bdate > DATE 1970-07-01' and salary >

More information

Chapter 3: Introduction to SQL

Chapter 3: Introduction to SQL Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query

More information

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 304 Introduction to Database Systems SQL DDL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Overview Structured Query Language or SQL is the standard query language

More information

CSC 261/461 Database Systems Lecture 6. Fall 2017

CSC 261/461 Database Systems Lecture 6. Fall 2017 CSC 261/461 Database Systems Lecture 6 Fall 2017 Use of WITH The WITH clause allows a user to define a table that will only be used in a particular query (not available in all SQL implementations) Used

More information

CS127 Homework #2. Due: September 27th, :59 P.M.

CS127 Homework #2. Due: September 27th, :59 P.M. CS127 Homework #2 Warmup #1 Suppose you have a relational database of Brown professors containing their Brown ID and their salary (integer). Write a tuple relational calculus formula that returns the ID(s)

More information

Trigger is a stored procedure which is called implicitly by oracle engine whenever a insert, update or delete statement is fired.

Trigger is a stored procedure which is called implicitly by oracle engine whenever a insert, update or delete statement is fired. Aim:- TRIGGERS Trigger is a stored procedure which is called implicitly by oracle engine whenever a insert, update or delete statement is fired. Advantages of database triggers: ---> Data is generated

More information

Database Management Systems,

Database Management Systems, Database Management Systems SQL Query Language (3) 1 Topics Aggregate Functions in Queries count sum max min avg Group by queries Set Operations in SQL Queries Views 2 Aggregate Functions Tables are collections

More information

SQL DATA DEFINITION LANGUAGE

SQL DATA DEFINITION LANGUAGE SQL DATA DEFINITION LANGUAGE DATABASE SCHEMAS IN SQL SQL is primarily a query language, for getting information from a database. DML: Data Manipulation Language SFWR ENG 3DB3 FALL 2016 MICHAEL LIUT (LIUTM@MCMASTER.CA)

More information

Why Relational Databases? Relational databases allow for the storage and analysis of large amounts of data.

Why Relational Databases? Relational databases allow for the storage and analysis of large amounts of data. DATA 301 Introduction to Data Analytics Relational Databases Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca DATA 301: Data Analytics (2) Why Relational Databases? Relational

More information

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

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement Chapter 4 Basic SQL Basic SQL SQL language Considered one of the major reasons for the commercial success of relational databases SQL Structured Query Language Statements for data definitions, queries,

More information

Table Joins and Indexes in SQL

Table Joins and Indexes in SQL Table Joins and Indexes in SQL Based on CBSE Curriculum Class -11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region Neha Tyagi, PGT CS II Shift Jaipur Introduction Sometimes we need an information

More information

Structure Query Language (SQL)

Structure Query Language (SQL) Structure Query Language (SQL) 1 6.12.2 OR operator OR operator is also used to combine multiple conditions with Where clause. The only difference between AND and OR is their behavior. When we use AND

More information

Intermediate SQL ( )

Intermediate SQL ( ) CSL 451 Introduction to Database Systems Intermediate SQL (4.1-4.4) Department of Computer Science and Engineering Indian Institute of Technology Ropar Narayanan (CK) Chatapuram Krishnan! Summary Join

More information

Question 1 (a) 10 marks

Question 1 (a) 10 marks Question 1 (a) Consider the tree in the next slide. Find any/ all violations of a B+tree structure. Identify each bad node and give a brief explanation of each error. Assume the order of the tree is 4

More information

From ER to Relational Model. Book Chapter 3 (part 2 )

From ER to Relational Model. Book Chapter 3 (part 2 ) From ER to Relational Model Book Chapter 3 (part 2 ) Logical DB Design: ER to Relational Translate Entity sets to tables: ssn name Employees lot CREATE TABLE Employees (ssn CHAR(11), name CHAR(20), lot

More information

Omar Abdul Baki ID: Database Systems Assignment 1 January 27, Question 1.

Omar Abdul Baki ID: Database Systems Assignment 1 January 27, Question 1. Question 1. Omar Abdul Baki ID: 110221969 Database Systems Assignment 1 January 27, 2008 1. Please refer to the attached diagram 1 2. Please refer to the attached diagram 1. 3. Doctor(SIN: string, name:

More information

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL RELATIONAL MODEL TO Data Model CONCEPTUAL DESIGN: ER TO RELATIONAL TO How to represent Entity sets, Relationship sets, Attributes, Key and participation constraints, Subclasses, Weak entity sets...? 2

More information

Introduction to Data Management. Lecture #5 (E-R Relational, Cont.)

Introduction to Data Management. Lecture #5 (E-R Relational, Cont.) Introduction to Data Management Lecture #5 (E-R Relational, Cont.) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v HW#1 is due

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Alexandra Roatiş David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Winter 2016 CS 348 SQL Winter

More information

MySQL Installation Guide (Windows)

MySQL Installation Guide (Windows) Step1- Install MySQL MySQL Installation Guide (Windows) The following description is based on MySQL 5.7.17 for Windows. Go to MySQL download page ( http://dev.mysql.com/downloads/mysql/ ). Click the Go

More information

SQL DATA DEFINITION LANGUAGE

SQL DATA DEFINITION LANGUAGE 9/27/16 DATABASE SCHEMAS IN SQL SQL DATA DEFINITION LANGUAGE SQL is primarily a query language, for getting information from a database. SFWR ENG 3DB3 FALL 2016 But SQL also includes a data-definition

More information

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables INDEX Exercise No Title 1 Basic SQL Statements 2 Restricting and Sorting Data 3 Single Row Functions 4 Displaying data from multiple tables 5 Creating and Managing Tables 6 Including Constraints 7 Manipulating

More information

Ref1 for STUDENT RECORD DB: Ref2 for COMPANY DB:

Ref1 for STUDENT RECORD DB: Ref2 for COMPANY DB: Lect#5: SQL Ref1 for STUDENT RECORD DB: Database Design and Implementation Edward Sciore, Boston College ISBN: 978-0-471-75716-0 Ref2 for COMPANY DB: Fund. of Database Systems, Elmasri, Navathe, 5th ed.,

More information

Comp 5311 Database Management Systems. 4b. Structured Query Language 3

Comp 5311 Database Management Systems. 4b. Structured Query Language 3 Comp 5311 Database Management Systems 4b. Structured Query Language 3 1 SQL as Data Definition Language Creates the Students relation. The type (domain) of each field is specified, and enforced by the

More information

SQL- Updates, Asser0ons and Views

SQL- Updates, Asser0ons and Views SQL- Updates, Asser0ons and Views Data Defini0on, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descrip0ons of the tables (rela0ons) of a database CREATE TABLE In SQL2, can use the

More information

Pushing Predicates into Recursive SQL Common Table Expressions

Pushing Predicates into Recursive SQL Common Table Expressions Pushing Predicates into Recursive SQL Common Table Expressions Marta Burzańska, Krzysztof Stencel, and Piotr Wiśniewski Faculty of Mathematics and Computer Science, Nicolaus Copernicus University, Toruń

More information

Lecture 19: Query Optimization (1)

Lecture 19: Query Optimization (1) Lecture 19: Query Optimization (1) May 17, 2010 Dan Suciu -- 444 Spring 2010 1 Announcements Homework 3 due on Wednesday in class How is it going? Project 4 posted Due on June 2 nd Start early! Dan Suciu

More information

1 SQL Structured Query Language

1 SQL Structured Query Language 1 SQL Structured Query Language 1.1 Tables In relational database systems (DBS) data are represented using tables (relations). A query issued against the DBS also results in a table. A table has the following

More information

DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E)

DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 1 DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE Updating Databases Using SQL Specifying Constraints as Assertions and Actions as Triggers Schema Change Statements in

More information

Unit 1 - Chapter 4,5

Unit 1 - Chapter 4,5 Unit 1 - Chapter 4,5 CREATE DATABASE DatabaseName; SHOW DATABASES; USE DatabaseName; DROP DATABASE DatabaseName; CREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype,... columnn

More information

SQL (Structured Query Language)

SQL (Structured Query Language) Lecture Note #4 COSC4820/5820 Database Systems Department of Computer Science University of Wyoming Byunggu Yu, 02/13/2001 SQL (Structured Query Language) 1. Schema Creation/Modification: DDL (Data Definition

More information

CSE 530A. ER Model to Relational Schema. Washington University Fall 2013

CSE 530A. ER Model to Relational Schema. Washington University Fall 2013 CSE 530A ER Model to Relational Schema Washington University Fall 2013 Relational Model A relational database consists of a group of relations (a.k.a., tables) A relation (table) is a set of tuples (rows)

More information

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

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210 SQL: Concepts Todd Bacastow IST 210: Organization of Data 2/17/2004 1 Design questions How many entities are there? What are the major entities? What are the attributes of each entity? Is there a unique

More information

Database design process

Database design process Database technology Lecture 2: Relational databases and SQL Jose M. Peña jose.m.pena@liu.se Database design process 1 Relational model concepts... Attributes... EMPLOYEE FNAME M LNAME SSN BDATE ADDRESS

More information

Physical Design. Elena Baralis, Silvia Chiusano Politecnico di Torino. Phases of database design D B M G. Database Management Systems. Pag.

Physical Design. Elena Baralis, Silvia Chiusano Politecnico di Torino. Phases of database design D B M G. Database Management Systems. Pag. Physical Design D B M G 1 Phases of database design Application requirements Conceptual design Conceptual schema Logical design ER or UML Relational tables Logical schema Physical design Physical schema

More information

Database Management Systems,

Database Management Systems, Database Management Systems SQL Query Language (2) 1 Topics Update Query Delete Query Integrity Constraint Cascade Deletes Deleting a Table Join in Queries Table variables More Options in Select Queries

More information

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement GIFT Department of Computing Science [Spring 2013] CS-217: Database Systems Lab-2 Manual Data Selection and Filtering using the SELECT Statement V1.0 4/12/2016 Introduction to Lab-2 This lab reinforces

More information

MySQL Installation Guide (Windows)

MySQL Installation Guide (Windows) Step1- Install MySQL MySQL Installation Guide (Windows) The following description is based on MySQL 5.7.10 for Windows. Go to MySQL download page (http://dev.mysql.com/downloads/mysql/). Click the Windows

More information

Chapter 2: The Relational Algebra

Chapter 2: The Relational Algebra CSE 303: Database RDBMS Architecture Lecture 11 How does a SQL engine work? Chapter 2: The Relational Algebra SQL Query Declarative query (from user) Relational Algebra (RA) Plan Translate to relational

More information

New Requirements. Advanced Query Processing. Top-N/Bottom-N queries Interactive queries. Skyline queries, Fast initial response time!

New Requirements. Advanced Query Processing. Top-N/Bottom-N queries Interactive queries. Skyline queries, Fast initial response time! Lecture 13 Advanced Query Processing CS5208 Advanced QP 1 New Requirements Top-N/Bottom-N queries Interactive queries Decision making queries Tolerant of errors approximate answers acceptable Control over

More information

Set theory is a branch of mathematics that studies sets. Sets are a collection of objects.

Set theory is a branch of mathematics that studies sets. Sets are a collection of objects. Set Theory Set theory is a branch of mathematics that studies sets. Sets are a collection of objects. Often, all members of a set have similar properties, such as odd numbers less than 10 or students in

More information