CS 3630 Database Design and Implementation. Base Table and View Base Table Stored on disk View Virtual table Records are not stored on disk Query is stored.

Slides:



Advertisements
Similar presentations
CS 3630 Database Design and Implementation. Where Clause and Aggregate Functions -- List all rooms whose price is greater than the -- average room price.
Advertisements

© Abdou Illia MIS Spring 2014
View (virtual table). View A VIEW is a virtual table A view contains rows and columns, just like a real table. The fields in a view are fields from one.
Chapter 4 Hotel (hotelno, hotelname, city)
1 Assignment 2 Relational Algebra Which tables? What operations? Common attributes? What result (attributes)? Syntax (Standard Notations and Symbols) –Product:
SQL Part II: Advanced Queries. 421B: Database Systems - SQL Queries II 2 Aggregation q Significant extension of relational algebra q “Count the number.
CS 3630 Database Design and Implementation. SQL Query Clause Select and From Select * From booking; select hotel_no, guest_no, room_no from booking; select.
Assignment6-1 Assignment6-2 Due Wednesday, March 13 1.
Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
Chapter 5 SQL. Agenda Data Manipulation Language (DML) –SELECT –Union compatible operations –Update database.
Chapter 6 SQL Homework.
Chapter 5 SQL Homework.
Using SQL to create tables Ways of using Databases.
View Sen Zhang. Views are very common in business systems users view of data is simplified a form of security - user sees only the data he/she needs to.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. SQL - part 2 - Database Management Systems I Alex Coman, Winter 2006.
View and Materialized view. What is a view? Logically represents subset of data from one or more table. In sql, a view is a virtual relation based on.
Introduction to Structured Query Language (SQL)
Project Phase I Phase II Due Monday, April 15 Groups 1.
Chapter 5 SQL. Agenda Data Manipulation Language (DML) –SELECT –Union compatible operations –Update database.
Microsoft Access 2010 Chapter 7 Using SQL.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
Microsoft Access 2010 Chapter 7 Using SQL. Change the font or font size for SQL queries Create SQL queries Include fields in SQL queries Include simple.
Chapter 5 SQL. Agenda Data Manipulation Language (DML) –SELECT –Union compatible operations –Update database.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
ITBIS373 Database Development
Project – Phase II Derive Database Schema from E-R Model DBDL.
1 CS 3630 Database Design and Implementation. 2 Sets Foundation of relational database. Basic Operations Power set Mapping.
SQL queries ordering and grouping and joins
Creating Tables and Inserting Records -- Not easy to edit! -- check constraints! Create table test1 ( C1 char(5) primary key, C2 Varchar2(15) not null.
Chapter 2 Views. Objectives ◦ Create simple and complex views ◦ Creating a view with a check constraint ◦ Retrieve data from views ◦ Data manipulation.
SQL - DML. Data Manipulation Language(DML) Are used for managing data: –SELECT retrieve data from the a database –INSERT insert data into a table –UPDATE.
Chapter 5 SQL: Data Manipulation Thomas Connolly, Carolyn Begg, Database System, A Practical Approach to Design Implementation and Management, 4 th Edition,
SQL SeQueL -Structured Query Language SQL SQL better support for Algebraic operations SQL Post-Relational row and column types,
SQL introduction 2013.
(C) 2000, The University of Michigan 1 Database Application Design Handout #5 February 4, 2000.
CS 3630 Database Design and Implementation. Joins -- For each booking, display the booking -- details with the room type and price Select B.*, rtype,
Views, Algebra Temporary Tables. Definition of a view A view is a virtual table which does not physically hold data but instead acts like a window into.
A table is a set of data elements (values) that is organized using a model of vertical columns (which are identified by their name) and horizontal rows.
(SQL - Structured Query Language)
INF 280 Database Systems SQL:Join
Populating and Querying tables Insert, Update, Delete and View (DML)
CS 3630 Database Design and Implementation. Null Value The value of an attribute could be NULL NOT known at the moment or NOT Applicable Example Cell.
WEEK# 12 Haifa Abulaiha November 02,
CS 3630 Database Design and Implementation. Where Clause and Aggregate Functions -- List all rooms whose price is greater than the -- average room price.
April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 1 Database Design SQL (2) John Wordsworth Department of Computer Science The University.
CS 3630 Database Design and Implementation. 2 Mathematical Relation A mathematical relation is a subset of a Cartesian Product. A1  A2  A3  …  An.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
SQL: Data Manipulation. Objectives Describe the purpose and importance of SQL. Demonstrate how to retrieve data from database using SELECT and: ▫Use compound.
CS 3630 Database Design and Implementation. Joins -- For each booking, display the booking -- details with the room type and price Select B.*, rtype,
CS 3630 Database Design and Implementation. Joins Retrieve data from two or more tables Join Conditions PK and FK (Natural Join) Other attributes (Theta.
SQL: Single Table Queries GROUP BY HAVING D. Christozov / G.Tuparov INF 280 Database Systems: SQL - Single Table queries 1.
Dr. Chen, Oracle Database System (Oracle) 1 Basic Nested Queries and Views Jason C. H. Chen, Ph.D. Professor of MIS School of Business Gonzaga University.
CS 3630 Database Design and Implementation
Assignment 2 Relational Algebra Which tables? What operations?
CS 3630 Database Design and Implementation
CS 3630 Database Design and Implementation
CS 3630 Database Design and Implementation
CS 3630 Database Design and Implementation
Latihan Answer the following questions using the relational schema from the Exercises at the end of Chapter 3: Create the Hotel table using the integrity.
Assignment 2.
Basic Nested Queries and Views
CS 3630 Database Design and Implementation
CS 3630 Database Design and Implementation
CS 3630 Database Design and Implementation
Chapter 2 Views.
CS 3630 Database Design and Implementation
Database systems Lecture 3 – SQL + CRUD
SQL Fundamentals in Three Hours
Chapter 2 Views.
Presentation transcript:

CS 3630 Database Design and Implementation

Base Table and View Base Table Stored on disk View Virtual table Records are not stored on disk Query is stored Records are generated when requested Looks like a table The users don’t know the difference 2

Horizontal views (a subset) Create View HotelsOfGlasgow as Select * From Hotel Where Name = 'Glasgow'; Desc HotelsOfGlasgow select * from HotelsOfGlasgow; Drop View RoomsInHotel; 3

Vertical View (Projection) Table Schema Booking (Hotel_no, Guest_no, Date_from, Date_to, Room_No) Create or replace view HotelBooking as Select Hotel_no, Room_No, Date_from, Date_to From Booking; -- Cannot use Create or replace for tables 4

Horizontal and Vertical View Create or replace view BookingOfGlasgow as Select Room_No, Date_from, Date_to From Booking Where Hotel_No in ('H05', 'H28'); 5

Horizontal and Vertical View -- using view HotelsOfGlasgow Create or replace view BookingOfGlasgow as Select Room_No, Date_from, Date_to From Booking Where Hotel_No in (Select Hotel_No From HotelsOfGlasgow); 6

Views based on grouping -- must give names to aggregate functions -- and all fields when one aggregate -- function exists. Create or replace view RoomsInHotel (Hotel_no, Room_Count) as Select Hotel_no, Count(*) From Room Group By Hotel_No; 7

Using Views in Queries Create or Replace View HotelG As Select Hotel_No From Hotel Where Name = 'Grosvenor'; Select * From Room Where Hotel_No in HotelG; ERROR at line 3: ORA-00904: "HOTELG": invalid identifier 8

Using Views in Queries Create or Replace View HotelG As Select Hotel_No From Hotel Where Name = 'Grosvenor'; Select * From Room Where Hotel_No in (Select * from HotelG); -- works if one value from the view Where Hotel_No = (Select * from HotelG); 9

Sub-Queries -- List guests who don’t have any bookings during -- April Select * From guest Where guest_no Not IN (Select Distinct guest_no From booking Where date_from <= '30-Apr-05' and date_to >= '01-Apr-05'); 10

Using View -- List guests who don’t have any bookings for -- April Create or Replace View BookingApril2005 as (Select guest_no From booking Where date_from <= '30-Apr-05' and date_to >= '01-Apr-05'); Select * From guest Where guest_no Not IN BookingApril2005; ORA-00904: "BOOKINGAPRIL2005": invalid identifier 11

Using View -- List guests who don’t have any bookings for -- April Create or Replace View BookingApril2005 as (Select guest_no From booking Where date_from <= '30-Apr-05' and date_to >= '01-Apr-05'); Select * From guest Where guest_no Not IN (Select * From BookingApril2005); 12

Using WITH With BookingApril2005 as (Select guest_no From booking Where date_from <= '30-Apr-05' and date_to >= '01-Apr-05') Select * From guest Where guest_no Not IN (Select * From BookingApril2005); Must have () for the With sub-query 13

Outer Join -- List guests who don’t have any bookings during -- April Select G.* From guest G Left Join Booking B on G.guest_no = B.guest_no and date_from <= '30-Apr-05' and date_to >= '01-Apr-05' Where B.guest_no is null; 14

Database System and File System Views in a File System? 15

Database Views Look like base tables Used in queries the same way as base tables Insert? Delete? Update? 16

Insert/Delete/Update Views -- View based on group Create or Replace view RoomsInHotel(Hotel, Room_Count) as Select Hotel_no, Count(*) From Room Group By Hotel_No; Insert into RoomsInHotel Values ('H11', 5); -- should insert 5 records into Room with 'H11' -- which 5 rooms? -- RNo (part of PK) not specified. -- Cannot do it! 17

Assignmet 9 Any Questions? 18

Phase III Any Questions? 19

Schedule Assignment 10 Start Friday Quiz 4 Friday May 1 Test 2 Wednesday, May 6 Phase IV Friday, May 8 Final Exam Thursday, May 14 7 PM (Group #10) 20