Views.

Slides:



Advertisements
Similar presentations
February 18, 2012 Lesson 3 Standard SQL. Lesson 3 Standard SQL.
Advertisements

Keys, Referential Integrity and PHP One to Many on the Web.
CSE 1561 A Brief MySQL Primer Stephen Scott. CSE 1562 Introduction Once you’ve designed and implemented your database, you obviously want to add data.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. SQL - part 2 - Database Management Systems I Alex Coman, Winter 2006.
Database Systems More SQL Database Design -- More SQL1.
Relational Database Design and MySQL
MIS2502: Data Analytics MySQL and SQL Workbench David Schuff
SQL's Data Definition Language (DDL) – View, Sequence, Index.
SQL/Lesson 4/Slide 1 of 45 Using Subqueries and Managing Databases Objectives In this lesson, you will learn to: *Use subqueries * Use subqueries with.
Oracle Database Administration Lecture 2 SQL language.
IST 210: ORGANIZATION OF DATA Chapter 1. Getting Started IST210 1.
Other database objects (Sequence). What Is a Sequence? A sequence: Automatically generates sequential numbers Is a sharable object Is typically used to.
Triggers A Quick Reference and Summary BIT 275. Triggers SQL code permits you to access only one table for an INSERT, UPDATE, or DELETE statement. The.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Views Lesson 7.
CpSc 3220 The Language of SQL The Language of SQL Chapters
M1G Introduction to Database Development 5. Doing more with queries.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Controlling User Access. 2 home back first prev next last What Will I Learn? Compare the difference between object privileges and system privileges Construct.
View 1. Lu Chaojun, SJTU 2 View Three-level vision of DB users Virtual DB views DB Designer Logical DB relations DBA DBA Physical DB stored info.
Database UpdatestMyn1 Database Updates SQL is a complete data manipulation language that can be used for modifying the data in the database as well as.
DataSet Your Database student test score Database Connection Your program needs to establish a connection to the database. Click on “Add New Data Source.”
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.
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.
Assignment 1 Uploaded to course website Due next Tuesday, Sep 1, at 11:59pm.
DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 1.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Function, Trigger used in PosgreSQL.
WEEK# 12 Haifa Abulaiha November 02,
Chapter 8 Views and Indexes 第 8 章 视图与索引. 8.1 Virtual Views  Views:  “virtual relations”. Another class of SQL relations that do not exist physically.
Relational Database Design and MySQL Charles Severance
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
Chapter 13 Triggers. Trigger Overview A trigger is a program unit that is executed (fired) due to an event Event such as updating tables, deleting data.
A Guide to MySQL 6. 2 Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT command.
1 CS 430 Database Theory Winter 2005 Lecture 13: SQL DML - Modifying Data.
Chapter 13 Triggers. Trigger Overview A trigger is a program unit that is executed (fired) due to an event Event such as updating tables, deleting data.
MYSQL AND MYSQL WORKBENCH MIS2502 Data Analytics.
Chapter 1. Getting Started IST 210: Organization of Data IST2101.
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Rob Gleasure robgleasure.com
CS SQL.
Rob Gleasure robgleasure.com
CpSc 3220 The Language of SQL
MySQL Subquery Source: Dev.MySql.com
Chapter 12 Subqueries and MERGE Oracle 10g: SQL
Tables and Triggers.
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
SQL – CRUD.
Indices.
ATS Application Programming: Java Programming
SQL – More Table Constraints
Implementing Triggers
mysql and mysql workbench
Views, Stored Procedures, Functions, and Triggers
Chapter 8 Advanced SQL Pearson Education © 2014.
SQL – Subqueries.
Insert, Update, Delete Manipulating Data.
SQL Views and Updates cs3431.
Chapter 2 Views.
Access: SQL Participation Project
Session #, Speaker Name Views 1/2/2019.
Chapter 8 Advanced SQL.
Creating complex queries using nesting
Database Systems: Design, Implementation, and Management Tenth Edition
A – Pre Join Indexes.
Assertions and Triggers
New Perspectives on Microsoft
Presentation transcript:

Views

Views are named SELECT statements id name 1 Josh 2 Tyler student_id time_inserted 1 12:40:00 2 14:37:34 students log CREATE VIEW name_and_time AS SELECT students.name, log.time_inserted FROM students INNER JOIN log ON students.id = log.student_id; name time_inserted Josh 12:40:00 Tyler 14:37:34 name_and_time

Views A view is a virtual table composed of the result-set of a select statement. A view has rows and columns (just like a table), but instead of holding data it itself, it just points to data held in other tables. You can treat a view like a table and do select statements on it, But views cannot be modified (no insert, update or delete) You can use a view like a temporary table. You can build the view from multple other tables with joins and/or filter certain rows with WHERE and so on. If the view's SELECT statement changes (modifications where made to the SELECT's underlying tables), the view automatically changes too.

View Example CREATE VIEW artist_and_albums AS SELECT Artist.Name, Album.Title, Album.AlbumId FROM Artist INNER JOIN Album ON Artist.ArtistId = Album.ArtistId; CREATE VIEW good_artists_and_albums AS SELECT * FROM artist_and_album WHERE NOT Name LIKE '%Kanye%'; CREATE VIEW good_tracks AS SELECT Tracks.* FROM Tracks INNER JOIN good_artists_and_albums ON Tracks.AlbumId = good_artists_and_albums.AlbumId;

When should you use views? When you want a read-only table made from data in other tables. To hide data complexity (for instance, complicated joins). Customizing the data, using functions and group by, to present the data in a new form. However, views are as slow as the query that creates them. And, views of views are even slower as they are basically nested SELECT subqueries.

View Lifespan A view lives only as long as the tables in its select statement. If the tables in the select statement are dropped, the view is also dropped. You can use the TEMPORARY keyword to indicate that the view should automatically be dropped when the current database connection is closed (meaning the view isn't persistent across connections). CREATE TEMPORARY VIEW something AS SELECT * FROM students; You can also remove a view manually with DROP VIEW: DROP VIEW something;

Views and Triggers You can attach a trigger to a view just like a table. However, you can't use BEFORE or AFTER triggers because they would never activate You can't modify a view But, you can use INSTEAD OF triggers. This is often done to make views look mutable like tables CREATE TRIGGER update_on_cool_tracks INSTEAD OF UPDATE ON cool_tracks BEGIN UPDATE Tracks SET Tracks.Name = NEW.Name WHEN Tracks.TrackId = NEW.TrackId; END;