CS 3630 Database Design and Implementation

Slides:



Advertisements
Similar presentations
CIT 613: Relational Database Development using SQL Revision of Tables and Data Types.
Advertisements

Chapter 4 Hotel (hotelno, hotelname, city)
Copyright © 2007, Oracle. All rights reserved Using Single-Row Functions to Customize Output Modified: October 21, 2014.
1 Assignment 2 Relational Algebra Which tables? What operations? Common attributes? What result (attributes)? Syntax (Standard Notations and Symbols) –Product:
OUTLINE OF THE LECTURE PART I GOAL: Understand the Data Definition Statements in Fig 4.1 Step1: Columns of the Tables and Data types. Step2: Single column.
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.
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.
Introduction to Oracle9i: SQL1 Selected Single-Row Functions.
Project Phase I Phase II Due Monday, April 15 Groups 1.
Databases Tutorial 2 Further Select Statements. Objectives for Week Data types Sort retrieved data Formatting output.
Chapter 5 SQL. Agenda Data Manipulation Language (DML) –SELECT –Union compatible operations –Update database.
Lecture 6 29/1/15. Number functions Number functions take numbers as input, change them, and output the results as numbers. 2.
Sorting data and Other selection Techniques Ordering data results Allows us to view our data in a more meaningful way. Rather than just a list of raw.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
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.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
SINGLE-ROW FUNCTIONS Lecture 9. SQL Functions Functions are very powerful feature of SQL and can be used to do the following:  Perform a calculation.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
CS 3630 Database Design and Implementation. Assignment 3 Style! Agreement between database designer and the client. UserName1_EasyDrive UserName2_EasyDrive.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
SQL queries ordering and grouping and joins
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
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.
Oracle Command Spool Spool C:\temp\Lab9.lst Select Hotel_no, room_no, type, price From Room Order by Hotel_no; Spool Off.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Chapter 5 SQL: Data Manipulation Thomas Connolly, Carolyn Begg, Database System, A Practical Approach to Design Implementation and Management, 4 th Edition,
Advanced SELECT Queries CS 146. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data Note the default formats… SELECT.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
SQL introduction 2013.
Structured Query Language
CS 3630 Database Design and Implementation. Joins -- For each booking, display the booking -- details with the room type and price Select B.*, rtype,
INF 280 Database Systems SQL:Join
Populating and Querying tables Insert, Update, Delete and View (DML)
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
ORDER BY clause in SELECT command: Normally, the result of the query will not be in ordered format. If we want to get the result of the query in specific.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
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.
CS 3630 Database Design and Implementation. Where Clause and Aggregate Functions -- List all rooms whose price is greater than the -- average room price.
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
Gollis University Faculty of Computer Engineering Chapter Five: Retrieval, Functions Instructor: Mukhtar M Ali “Hakaale” BCS.
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.
Database Design lecture 3_2 Slide 1 Database Design Lecture 3_2 Data Manipulation in SQL Simple SQL queries References: Text Chapter 8 Oracle SQL Manual.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
CS 3630 Database Design and Implementation
CS 3630 Database Design and Implementation
Assignment 2 Relational Algebra Which tables? What operations?
Managing Tables, Data Integrity, Constraints by Adrienne Watt
CS 3630 Database Design and Implementation
CS 3630 Database Design and Implementation
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
CS 3630 Database Design and Implementation
CS 3630 Database Design and Implementation
Assignment 2.
SQL 101 3rd Session.
CS 3630 Database Design and Implementation
Chapter 4 Summary Query.
CS 3630 Database Design and Implementation
Single-Row Functions Lecture 9.
Section 4 - Sorting/Functions
Introduction to SQL Server and the Structure Query Language
Lab 2: Retrieving Data from the Database
Presentation transcript:

CS 3630 Database Design and Implementation

Mapping E-R Model to Relational Schema Due Wednesday, April 4, by 5 pm Project Phase II Mapping E-R Model to Relational Schema Due Wednesday, April 4, by 5 pm

SQL Query Clause Select and From From booking; select hotel_no, guest_no, room_no from booking; select Distinct hotel_no, guest_no, room_no -- Remove duplicate records -- Unique also works Should be updated using tables from Assignment 7

Oracle Command Column (Col) Column Hotel_no format A9 Col Hotel_No format a9 heading 'Hotel No' -- This also work col Hotel_no format a9 heading "Hotel No" -- to get leading decimal digits Column Price format $999.99 heading 'Price/Night' -- to get leading 0s Column Price format $099.99 heading 'Price/Night' Col Date_To format a16 heading 'Date of Leaving' Col Date_From format a16 heading 'Date of|Arrival' Select * from Room; Select * from Booking; Clear col

Clause Where Select * From Room Where RType = 'Single‘; -- Where clause to specify the condition -- Operators And/Or Where Price > 35 and RType = 'Single‘; -- Where Price > 35 or RType = 'Single'

Operator NOT (!) Select * From Room Where Price > 35 and RType != 'Family'; -- Where Price > 35 and Not (RType = 'Family‘) -- Where Price > 35 and NOT RType = 'Family‘ -- Not working: -- Where Price > 35 and !(RType = 'Family‘)

Operator NOT (!) Select * From Room Where Not (Price > 35 and RType = 'Family'); -- Not the same! Where Not Price > 35 and RType = 'Family'; --Where (Not Price > 35) and RType = 'Family'; --Where Price <= 35 and RType = 'Family';

Operator Between Select * From Room Where Price between 30 and 45; -- inclusive Where Price Not between 30 and 45; -- Where Not Price between 30 and 45;

Operator IN Select * From Room Where Price in (30, 40, 45); -- Same as -- Where Price = 30 or Price = 40 or Price = 45 Where Price Not in (30, 40, 45); -- Where Not Price in (30, 40, 45);

Comparing Strings Operator Like and % Select * From guest Where guest_name = 'Mary Tregear' Where guest_name like 'M%'; -- All guests with name beginning with 'M‘ -- %: any string of zero or more chars

Operator Like and Char ‘_’ -- All records whose Fname has 'M' for 3rd position Select * From Guest Where guest_name like '__M%'; -- _: any single char

Null Value Select * From Guest Where Address = null; -- No row is selected -- null != null Where Address is null; -- Some rows may be selected

Changing Headings -- use " " for heading -- Use ' ' for string -- With or without "AS" Select Guest_no, Guest_name as "Guest Name" From Guest; Select Guest_no, Guest_name "Guest Name" Select Guest_no, Guest_name as GuestName Select Guest_no, Guest_name GuestName

Sorting the Result Select * From Room Order by Price desc; -- ASC is the default

Sorting the Result Select * From Room Order by Hotel_No, Price desc; -- Sorting first on Hotel_No (asc), -- then on Price (desc) -- ASC is the default

Sorting the Result Select Hotel_No, Room_No, RType From Room Order by Hotel_No, Price desc; -- Price may not be selected

Sorting the Result -- Can be used in Order by Select Guest_no, Guest_name as GuestName From Guest Order by GuestName; Select Guest_no, Guest_name as "Guest Name" Order by "Guest Name“;

Numeric Operators/Functions Select Hotel_No, Room_No, Price * 0.90 "Discount Price" From Room; -- Where Hotel_No = ‘H01'; -- operators: +, -, /, * -- functions: ceil, floor, mod, power, sign, sqrt

Character Functions Select Guest_Name || ' From ' || Address From Guest Where Address is not null;

Character Functions Lower Upper Initcap length replace -- Replace all occurrences substr Instr

Character Functions Select substr(Guest_name, 1, 9) From Guest; -- substr(Guest_name, 1, 9) up to 9 characters Select * From Guest where instr(Guest_name, 'T', 6) > 0; where instr(Guest_name, 'T', 7) > 0;

Due Friday, April 6 Formatting Style Assignment 8 Due Friday, April 6 Formatting Style