Final-Exam Revision Instructor: Mohamed Eltabakh 1.

Slides:



Advertisements
Similar presentations
DB glossary (focus on typical SQL RDBMS, not XQuery or SPARQL)
Advertisements

Dr. Alexandra I. Cristea CS 252: Fundamentals of Relational Databases: SQL5.
BACS 485—Database Management Advanced SQL Overview Advanced DDL, DML, and DCL Commands.
TURKISH STATISTICAL INSTITUTE 1 /34 SQL FUNDEMANTALS (Muscat, Oman)
1 Constraints, Triggers and Active Databases Chapter 9.
AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
Revision of course For examination purposes. Outline of Examination Question 1 is compulsory and is worth 40%. There are five other questions, of which.
Access - 1 Table Query (View) FormReport Database Application Basic Database Objects Relationships among Access Database Objects A saved SELECT query is.
1 SQL-Structured Query Language SQL is the most common language used for creating and querying relational databases. Many users can access a database applications.
SQL Exercises1 Revising RDB and SQL CTEC2902 Advanced Programming.
Advanced SQL: Stored Procedures Instructor: Mohamed Eltabakh 1.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
TEMPDB Capacity Planning. Indexing Advantages – Increases performance – SQL server do not have to search all the rows. – Performance, Concurrency, Required.
Oracle Database Administration Lecture 2 SQL language.
DAY 12: DATABASE CONCEPT Tazin Afrin September 26,
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
1. 1. Which type of argument passes a value from a procedure to the calling program? A. VARCHAR2 B. BOOLEAN C. OUT D. IN 2.
Advanced SQL: Cursors & Stored Procedures
Advanced SQL Instructor: Mohamed Eltabakh 1 Part II.
Revision Instructor: Mohamed Eltabakh 1.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Final Exam Revision Instructor: Mohamed Eltabakh 1.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Advanced SQL: Triggers & Assertions
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Announcements Midterm is Nov. 22 (8:15am – 9:45am) Covers until the end of Normalization You answer in the same exam paper Closed-Book, One sheet is allowed.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
CMPT 258 Database Systems Midterm Review. Regarding the Exam Oct 15 Thursday Close book Cheat sheet (1 side of an A4 paper)
SQL Miscellaneous Topics. Views A database view is: – a virtual or logical table based on a query. – a stored query. CREATE VIEW viewname AS query; –CREATE.
Advanced Databases More Advanced PL/SQL Programing 1.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
1 CS3431 – Database Systems I Logistics Instructor: Mohamed Eltabakh
Oracle & SQL. Oracle Data Types Character Data Types: Char(2) Varchar (20) Clob: large character string as long as 4GB Bolb and bfile: large amount of.
IT420: Database Management and Organization Triggers and Stored Procedures 24 February 2006 Adina Crăiniceanu
Advanced SQL: Cursors & Stored Procedures Instructor: Mohamed Eltabakh 1.
Thinking in Sets and SQL Query Logical Processing.
SQL: Structured Query Language Instructor: Mohamed Eltabakh 1 Part II.
MIDTERM REVIEW IST 210 Organization of Data IST210 1.
Using Structured Query Language (SQL) NCCS Applications –MS Access queries (“show SQL”) –SAS (PROC SQL) –MySQL (the new dataserver) –Visual Foxpro Other.
CS3431-B111 CS3431 – Database Systems I Logistics Instructor: Mohamed Eltabakh
Big Data Yuan Xue CS 292 Special topics on.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
SQL Query Getting to the data ……..
Structured Query Language
Indices.
Query-by-Example (QBE)
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
Latihan Create a separate table with the same structure as the Booking table to hold archive records. Using the INSERT statement, copy the records from.
SQL 101.
Structured Query Language
Advanced SQL: Views & Triggers
Instructor: Mohamed Eltabakh
Logistics Instructor: Mohamed Eltabakh
Instructor: Mohamed Eltabakh
Instructor: Mohamed Eltabakh
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
Database systems Lecture 3 – SQL + CRUD
Instructor: Mohamed Eltabakh
SQL: Structured Query Language
CS561-Spring 2012 WPI, Mohamed eltabakh
Advanced Topics: Indexes & Transactions
SQL: Structured Query Language
Instructor: Mohamed Eltabakh
Presentation transcript:

Final-Exam Revision Instructor: Mohamed Eltabakh 1

Reminder…..Final Exam Dec. 13, at 8:15am – 9:30am (75 mins) Closed book, open sheet Answer in the same exam sheet Material Included ERD SQL (Select, Insert, Update, Delete) Views, Triggers, Assertions Cursors, Stored Procedures/Functions Material Excluded Relational Model & Algebra Normalization Theory ODBC/JDBC Indexes and Transactions

SQL Commands 3

4 Question 1

5 Question 2 Select the most expensive generic medicine Select * From Medicine Where UnitPrice = ( Select max(unitPrice) From Medicine Where genericFlag = ‘T’) And genericFlag = ‘T’;

6 Question 2: Another way Select the most expensive generic medicine Select * From ( Select * From Medicine Where genericFlag = ‘T’ Order By UnitPrice Desc) Where rownum = 1; Use of rownum (Oracle specific) Must be in outer select after sorting

7 Question 3

8 Use of rownum (Oracle specific) Question 3: Another Way

9 Question 4 Delete prescription lines for prescriptions written on date ‘Jan ’ Delete From Prescription_Medicine Where prescription_id in ( Select id From Prescription Where date = ‘Jan ’);

10 Question 5 Delete prescriptions that have no lines (no records in prescription_medicine) Delete From Prescription Where id not in ( Select prescription_id From prescription_medicine);

11 Question 6 Select patients who have no primary doctors Select * From Patient Where primaryDoctor_SSN is null;

12 Question 7 Report the prescription id and its total cost of prescriptions having total cost between $100 and $200. Sort ascending based on the total cost Select prescription_id, sum(unitPrice * NumOfUnits) As totalCost From Medicine M, Prescription_Medicine PM Where M.TradeName = PM.TradeName Group By prescription_id Having totalCost > 100 And totalCost < 200 Order By totalCost;

13 Question 8 Double the number of units in prescription id and tradeName ‘Aspirin’. Update Prescription_Medicine Set NumOfUnits = NumOfUnits * 2 Where Prescription_id = And tradeName = ‘Aspirin’;

14 Question 9 For medicines in prescription 11111, double their number of units if is it currently below 5 Update Prescription_Medicine Set NumOfUnits = NumOfUnits * 2 Where Prescription_id = And tradeName in (Select tradeName From prescription_medicine Where prescription_id = And numOfUnits < 5);

Advanced SQL Commands 15

16 Question 10 Create a view that reports the trade name, unit price, and the generic flag of the most expensive and cheapest medicines.

17 Question 11 Create a view that reports the trade name, unit price, and the generic flag of the most expensive and cheapest medicines. Each record should have an indicator on whether it is the most expensive or cheapest. Create View MedicineView2 AS Select TradeName, unitPrice, genericFlag, ‘Max’ as type From Medicine Where unitPrice in (Select max(unitPrice) price From Medicine) Union Select TradeName, unitPrice, genericFlag, ‘Min’ as type From Medicine Where unitPrice in (Select min(unitPrice) price From Medicine);

18 Question 12 Using the view created in Question 11, count the number of trade names having the most expensive price. Select Count(*) From MedicineView2 Where type = ‘Max’;

19 Question 13 Create an assertion that ensures that no prescription has a tradeName having number of units > 10 Create Assertion NumUnitsBelowTen As ( 10 >= All (Select NumOfUnits From Prescription_Medicine) );

20 Question 14 Create an assertion that ensures any primary doctor has at least 3 years of experience Create Assertion NumUnitsBelowTen As ( Not Exists (Select * From doctor D, patient P Where D.SSN = P.PrimaryDoctor_SSN And YearsOfExperience < 3) );

21 Question 15 Create a stored function that takes a date as a parameter and returns the number of prescriptions on that date Create Function NumPrescriptions (inDate IN date) Return int As temp int; Begin Select count(*) into temp From prescription where date = inDate; return temp; End;

22 Question 16 Using the function created in Question 15, report the prescriptions written on a date in which more than 10 prescriptions have been written Select * From prescription Where NumPrescriotions(date) > 10;

23 Question 17 Create trigger that ensures that if the medicine is generic, then its unit price is below $100, and if it is not generic then its unit price >= $100 Create Trigger UnitPrice Before Insert Or Update On Medicine For Each Row Begin IF (:new.GenericFlag = ‘T’ and :new.UnitPrice >= 100) Then RAISE_APPLICATION_ERROR(-20004, ‘Price should be < $100’); ELSIF (:new.GenericFlag = ‘F’ and :new.UnitPrice < 100) Then RAISE_APPLICATION_ERROR(-20004, ‘Price should be >= $100’); END IF; End;

Evaluation Forms Course Number: CS3431 Course Name: Database Systems I Term: B11 Instructor Name: Mohamed Eltabakh TAs Name: Kenneth Loomis Name: Chiying Wang 24