1 Agenda for Class 03/07/2006  Learn to simplify queries for complex questions through the use of views.  Concept of a view.  Syntax to create and access.

Slides:



Advertisements
Similar presentations
Welcome to CODE SPREAD Simple Concepts of Coding | Programming.
Advertisements

Organisation Of Data (1) Database Theory
4d. Structured Query Language – JOIN Operation Lingma Acheson Department of Computer and Information Science IUPUI CSCI N207 Data Analysis with Spreadsheets.
Creating Tables. 2 home back first prev next last What Will I Learn? List and provide an example of each of the number, character, and date data types.
Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS.
Designing a Database Unleashing the Power of Relational Database Design.
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.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
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.
Structured Query Language Chapter Three DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Attribute databases. GIS Definition Diagram Output Query Results.
INTEGRITY Enforcing integrity in Oracle. Oracle Tables mrobbert owner granted access.
Transaction Processing Systems, & Management Information Systems.
Microsoft Access Database software. What is a database? … a database is an organized collection of data. A collection of data of similar information compiled.
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
Organizing Information Digitally Norm Friesen. Overview General properties of digital information Relational: tabular & linked Object-Oriented: inheritance.
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
 A databases is a collection of data organized to make it easy to search and easy to retrieve in a useful, usable form.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
University of Sunderland COM 220Lecture Two Slide 1 Database Theory.
Programming using C# Joins SQL Injection Stored Procedures
1 Agenda – 03/25/2014 Login to SQL Server 2012 Management Studio. Answer questions about HW#7 – display answers. Exam is 4/1/2014. It will be in the lab.
HSCI 709 SQL Data Definition Language. SQL Standard SQL-92 was developed by the INCITS Technical Committee H2 on Databases. SQL-92 was designed to be.
Computer Science & Engineering 2111 Lecture 11 Querying a Database 1.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Database A database is a collection of data organized to meet users’ needs. In this section: Database Structure Database Tools Industrial Databases Concepts.
Views. Logical data is how we want to see the current data in our database. Physical data is how this data is actually placed in our database.
“INTRODUCTION TO DATABASE AND SQL”. Outlines 2  Introduction To Database  Database Concepts  Database Properties  What is Database Management System.
MIS 327 Database Management system 1 MIS 327: DBMS Dr. Monther Tarawneh Dr. Monther Tarawneh Week 2: Basic Concepts.
 Agenda 2/20/13 o Review quiz, answer questions o Review database design exercises from 2/13 o Create relationships through “Lookup tables” o Discuss.
Agenda for 02/21/2006 Learn how to use more than one table in a query. Discuss how DBMS processes multiple tables. Explain the different types of joins.
1 Agenda – 10/24/2013 Answer questions from lab on 10/22. Present SQL View database object. Present SQL UNION statement.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
Database Management System (DBMS) an Introduction DeSiaMore 1.
Views Lesson 7.
Databases MIS 21. Some database terminology  Database: integrated collection of data  Database Management System (DBMS): environment that provides mechanisms.
1 Agenda for Class 03/02/2006  Do SQL join “quiet participation” exercise in class.  Learn to simplify queries for complex questions through the use.
INFO1408 Database Design Concepts Week 15: Introduction to Database Management Systems.
Agenda for 02/16/2006 Answer any questions about SQL project. Do you want to see any of the answers for the queries? Discuss additional formatting options.
Programming in R SQL in R. Running SQL in R In this session I will show you how to: Run basic SQL commands within R.
Component 4: Introduction to Information and Computer Science Unit 6a Databases and SQL.
SQL Views Chapter 3A. Appendix Objectives Learn basic SQL statements for creating views Learn basic SQL statements for using views Understand the reasons.
Indexes and Views Unit 7.
Chapter 13 Views Oracle 10g: SQL. Oracle 10g: SQL2 Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE VIEW command Employ the.
(SQL - Structured Query Language)
+ Complex SQL Week 9. + Today’s Objectives TOP GROUP BY JOIN Inner vs. Outer Right vs. Left.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
Agenda for Class - 03/04/2014 Answer questions about HW#5 and HW#6 Review query syntax. Discuss group functions and summary output with the GROUP BY statement.
For more course tutorials visit CIS 336 All iLabs Week 1 to Week 7 Devry University CIS 336: All iLabs Week 1 to Week 7: Devry University.
Create Views Using T-SQL Database Administration Fundamentals LESSON 2.3a.
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
DAY 20: ACCESS CHAPTERS 5, 6, 7 Larry Reaves October 28,
IFS180 Intro. to Data Management Chapter 10 - Unions.
SQL Introduction SQL stands for “Structured Query Language” and can be pronounced as “SQL” or “sequel – (Structured English.
“Introduction To Database and SQL”
Table spaces.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
3d. Structured Query Language – JOIN Operations
© 2016, Mike Murach & Associates, Inc.
This shows the user interface and the SQL Select for a situation with two criteria in an AND relationship.
“Introduction To Database and SQL”
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
CSCI 2141 – Intro to Database Systems
CS 440 Database Management Systems
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Structured Query Language
Presentation transcript:

1 Agenda for Class 03/07/2006  Learn to simplify queries for complex questions through the use of views.  Concept of a view.  Syntax to create and access a view.  Uses of a view.  Practice writing SQL without the use of a computer.

3 What is a SQL View?  A “virtual” table.  A set of SQL statements that creates a result table which can be accessed by other SQL statements.  Similar to a function in another programming language, except that the end-product of the view is a named result table.  A database object.  A view is stored in the database.  A view contains no data of its own.  A view relies on the data in the base tables used to create the view.  A set of stored SQL code.  Stores code; not data.

What is the name of the employee who has some time recorded in the TIME table, but has the least amount of time performing work with the word “java” in the description? SELECTemp.empid, emp.name, sum(amount/60) hours_worked FROMemp INNER JOINtime ONemp.empid = time.empid INNER JOINwork ONwork.worktypeid = time.worktypeid WHERElower(description) LIKE 'java%' GROUP BYemp.empid, emp.name HAVINGsum(amount/60) = (SELECT min(sum(amount/60)) FROM time INNER JOIN work ON time.worktypeid = work.worktypeid WHERE lower(description) LIKE 'java%' GROUP BY time.empid, time.worktypeid);

CREATE OR REPLACE VIEW view_hours AS SELECTemp.empid, emp.name, time.worktypeid, lower(description) description, nvl(sum(time.amount/60),0) hoursworked FROM emp INNER JOINtime ONemp.empid = time.empid INNER JOIN work ONtime.worktypeid = work.worktypeid GROUP BYemp.empid, emp.name, time.worktypeid, description; Create a View Use the View SELECTview_hours.empid, view_hours.name, hoursworked FROMview_hours WHEREdescription like 'java%' ANDhoursworked = (SELECT min(hoursworked) FROM view_hours WHERE description like 'java%');

6 Uses of views  Views are used to:  Provide easier access to data.  Enhance security.  Lessen the visible complexity of the database.  Views are usually created by the DBA for a defined workgroup of people.  Programmers.  Users.  Users in a specific functional area.

7 When should views be used?  Use to protect sensitive data.  Example: Can create a view of personnel data that does not include salary data.  Use to break down complicated queries into modular components.  Use for group/aggregate functions.  Use for multiple table joins.

8 Rules-of-thumb about views  Avoid extra joins. Avoid creating a view with an underlying table, and then using that view to join the result table from the view with that same table in a query. Try to use the view to replace the table, so that you don’t have to use the table again.  Make views flexible. Create views that can be used by more than one query. Anticipate how the data will be accessed so that one view could be used in more than one situation.  Make views useful. Be sure to include relevant foreign keys in a view.

9 Looking at the details of a view in Oracle You can look at all views or just one view. SELECTview_name FROMuser_views; Results from the statement above: VIEW_NAME EMP_TIME TIME_BY_WORK VIEW_HOURS The views above are in the account I used to show the results of the statement. Your names will be different.

10 Looking at the code in a view SELECT text FROM user_views WHERE LOWER(view_name) = ‘hours_by_emp' Results from the query above: TEXT SELECT employee.empid, name, nvl(sum(amount/60),0) hoursworked FROM employ

11 Looking at all the code in a view  The column “text” is a long data type.  Long data types will truncate at a pre-determined size.  Sometimes you won’t see all your SQL code in the “text” column because of the truncation.  To enlarge the size of display for long data types, do the following: SET LONG 500 (or whatever number of characters in the text of the view that you want to see displayed.)