Database Management Systems

Similar documents
Introduction to Data Management. Lecture #4 (E-R Relational Translation)

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

Database Management Systems,

Score. 1 (10) 2 (10) 3 (8) 4 (13) 5 (9) Total (50)

Introduction to Data Management. Lecture #5 Relational Model (Cont.) & E-Rà Relational Mapping

The Relational Model. Week 2

The Relational Data Model. Data Model

Relational data model

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Database Management Systems,

Database Management Systems,

Relational Query Languages

The Relational Model 2. Week 3

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

Database Applications (15-415)

The Relational Model. Chapter 3

1 (10) 2 (8) 3 (12) 4 (14) 5 (6) Total (50)

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

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

Chapter 2: Intro to Relational Model

The University of Nottingham

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

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

CompSci 516 Database Systems. Lecture 2 SQL. Instructor: Sudeepa Roy

The Relational Model

COMP 244 DATABASE CONCEPTS AND APPLICATIONS

The Relational Data Model. Data Models. Relational vs Semistructured. Structure Operations - Constraints

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

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity

The SQL data-definition language (DDL) allows defining :

ER to Relational Model. Professor Jessica Lin

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

SQL: The Query Language Part 1. Relational Query Languages

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages

EECS 647: Introduction to Database Systems

CS425 Fall 2016 Boris Glavic Chapter 2: Intro to Relational Model

CS127 Homework #3. Due: October 11th, :59 P.M. Consider the following set of functional dependencies, F, for the schema R(A, B, C, D, E)

CIS 330: Applied Database Systems. ER to Relational Relational Algebra

Chapter 3: Introduction to SQL

Translating an ER Diagram to a Relational Schema

CSE 344 Midterm. Wednesday, February 19, 2014, 14:30-15:20. Question Points Score Total: 100

QUETZALANDIA.COM. 5. Data Manipulation Language

CS2300: File Structures and Introduction to Database Systems

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615

CSEN 501 CSEN501 - Databases I

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

CSCB20 Week 3. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

CSCB20 Week 2. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

Review: Where have we been?

Introduction to Data Management. Lecture #6 E-Rà Relational Mapping (Cont.)

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

CS425 Midterm Exam Summer C 2012

Announcements If you are enrolled to the class, but have not received the from Piazza, please send me an . Recap: Lecture 1.

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

CS3DB3/SE4DB3/SE6M03 TUTORIAL

The Relational Model

QQ Group

Lecture 2 SQL. Announcements. Recap: Lecture 1. Today s topic. Semi-structured Data and XML. XML: an overview 8/30/17. Instructor: Sudeepa Roy

CSE 344 Midterm. Wednesday, February 19, 2014, 14:30-15:20. Question Points Score Total: 100

Intermediate SQL ( )

Database Management Systems. Chapter 3 Part 1

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

Announcements (September 18) SQL: Part II. Solution 1. Incomplete information. Solution 3? Solution 2. Homework #1 due today (11:59pm)

Database Systems ( 資料庫系統 )

The Relational Model (ii)

Exam code: Exam name: Database Fundamentals. Version 16.0

Chapter 3: Introduction to SQL

The Relational Model. Roadmap. Relational Database: Definitions. Why Study the Relational Model? Relational database: a set of relations

Midterm Exam (Version B) CS 122A Spring 2017

Review. The Relational Model. Glossary. Review. Data Models. Why Study the Relational Model? Why use a DBMS? OS provides RAM and disk

SQL: Part II. Announcements (September 18) Incomplete information. CPS 116 Introduction to Database Systems. Homework #1 due today (11:59pm)

ALTER TABLE Statement

VIEW OTHER QUESTION PAPERS

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

Midterm Exam. October 30th, :15-4:30. CS425 - Database Organization Results

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

Structure Query Language (SQL)

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

Database Systems. Course Administration. 10/13/2010 Lecture #4

Working with Databases and Java

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

Chapter 6 - Part II The Relational Algebra and Calculus

SQL: Part III. Announcements. Constraints. CPS 216 Advanced Database Systems

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

Relational model and basic SQL

Announcements (September 14) SQL: Part I SQL. Creating and dropping tables. Basic queries: SFW statement. Example: reading a table

Chapter 2: Intro to Relational Model

Homework 2. Develop an EER model for the following situation using the EER diagram,

Lecture 2 SQL. Instructor: Sudeepa Roy. CompSci 516: Data Intensive Computing Systems

CMPT 354: Database System I. Lecture 3. SQL Basics

Name: Database Systems ( 資料庫系統 ) Midterm exam, November 15, 2006

COUNT Function. The COUNT function returns the number of rows in a query.

CIS 330: Applied Database Systems

CS 4604: Introduction to Database Management Systems. B. Aditya Prakash Lecture #2: The Relational Model and Relational Algebra

Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

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

Database Technology Introduction. Heiko Paulheim

Database Views & Stored Procedures. Hans-Petter Halvorsen, M.Sc.

Introduction to Databases

Keys are fields in a table which participate in below activities in RDBMS systems:

Transcription:

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 each field determine the null constraint too. Create table ( BookTitle varchar(255) NOT NULL, Author varchar(255) NOT NULL, Publisher varchar(255) NOT NULL, yearpublished integer, ISBN varchar(20) PRIMARY KEY ) 2

Give the definitions of the followings: Relation Relation Schema Database Schema Foreign Key Constraint Transaction Schema Entity 3

The following question considers a company which is selling some products to its customers. Write SQL queries to create tables for customers and products of the company. The customer table should have ID, name, address, phone fields. The product table should include ProductID, name, type, and price fields. Your tables should have primary keys. For each field determine the null constraint too. Assume orders from customers for different products are received by the company. Besides, assume each order can include several items of only one product type. The number of items ordered and the order date should also be stored. Explain how the order can be added to your database. Write necessary SQL commands. 4

Create table product(productid integer Primary key, name varchar(255) not null, type varchar(255), price real ) Create table customer (ID integer primary key, name varchar(255) not null, address varchar(255), phone varchar(20)) Create table order (pid integer references product(productid), cid integer references customer(id), quantity integer not null, orderdate date, PRIMARY KEY (pid, cid) ) 5

Assume the lists of instructors and courses are stored in two tables. The main attributes are given as below: Instructor< ID, Name, Office, Department > Course<ID, Name, Credits, Department> Write necessary SQL commands to create the tables. Consider necessary constraints. Assuming that the tables should include the relationships between a course and the instructor offering that course, make necessary changes in your tables Write SQL commands to insert a course and an instructor data into the tables Write SQL command to change the office of the instructor you just entered. 6

CREATE TABLE Instructor ( ID Integer PRIMARY KEY, Name Varchar(255) NOT NULL, Office Varchar(255), Department Varchar(255) ) CREATE TABLE Course( ID Integer PRIMARY KEY, Name Varchar(255) NOT NULL, Credits Integer NOT NULL, Department Varchar(255) NOT NULL) 7

Assuming that the tables should include the relationships between a course and the instructor offering that course, make necessary changes in your tables CREATE TABLE Course( ID Varchar(255) PRIMARY KEY, Name Varchar(255) NOT NULL, Credits Integer NOT NULL, Department Varchar(255) NOT NULL, OfferedBy Integer References Instructor(ID)) 8

Write SQL commands to insert a course and an instructor data into the tables Insert Into Instructor Values ( 100, hasan, B101, Economy ) Insert Into Course Values ( ECON200, Accounting, 3, Economy, 100) 9

Write SQL command to change the office of the instructor you just entered. UPDATE Table Instructor SET Office = B201 Where ID = 100 10

What does the following query compute? SELECT S.name, E.cid FROM Students S, Enrolled E WHERE S.sid=E.sid AND E.grade= A sid name department 53650 Smith Computer 53666 John Electronics 53831 Mary Management 11

In the following tables, delete statement is run as shown below. Explain what problem(s) may arise and what solutions are available for them. Book<BookID, Title, Author, Publisher> User<UserID, Name, Address> Borrowed<BookID, UserID, DateBorrowed, DateDue> The query is: DELETE FROM Book WHERE BookID = 37623 12

After deleting a book, the records from the borrowed table which refer to the deleted book will be invalid. As the solution we can use cascade delete which deletes all records in the borrowed table which refer to this book 13

Relational Algebra Write a relation algebra expression to find the names and surnames of employees who work in Administration department. Assume Employee relation is defined as below: Employee<name, surname, department, city, salary> Π name,surname (σ department= Administration (Employee)) 14

Relational Algebra Consider the relations r1 and r2 as given below. Write a relational algebra instruction to join r1 and r2 (naturaljoin) Show the result of join operation as a relation Write a relation algebra instruction to find the name of all employees in the department where mori is the head 15

r1 r2 Employee Department Head Black Production Mori White Production Mori Write a relation algebra instruction to find the name of all employees in the department where mori is the head Π name (σ Head= Mori (r1 r2)) 16

Relational Algebra Write a relational algebra expression to find the names, surnames, and the name of the department of employees who work in a department located in Ankara. Employee and department relations are defined as below: Employee<name, surname, DepartmentCode, Age, salary> Department<DepartmentCode, DeptName, Location> Π name,surname,deptname (σ Location= Ankara Employee Department ) 17