20761B 12: Using Set Operators Module 12   Using Set Operators.

Slides:



Advertisements
Similar presentations
Virtual training week 4 structured query language (SQL)
Advertisements

Introduction to Structured Query Language (SQL)
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
Using T-sql scripts. Migrating Sql Database to SQL Azure Database Create the Test Database In SQL Server Management Studio, on the File menu, point to.
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
1 Working with MS SQL Server Textbook Chapter 14.
06 | Modifying Data in SQL Server Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
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.
Installation Oracle 11g Express 2 double click the "setup" button to install the Oracle.
 CONACT UC:  Magnific training   
Software-Projekt 2008 Seminarvortrag“Short tutorial of MySql“ Wei Chen Verena Honsel.
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
2 Copyright © 2008, Oracle. All rights reserved. Building the Physical Layer of a Repository.
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.
3 A Guide to MySQL.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
Web Systems & Technologies
Running a Forms Developer Application
Rob Gleasure robgleasure.com
Using DML to Modify Data
Introduction to Microsoft SQL Server 2016
Basic Database Concepts
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Introduction to T-SQL Querying
02 | Advanced SELECT Statements
Sorting and Filtering Data
Querying Multiple Tables
Jon Galloway | Tech Evangelist Christopher Harrison | Head Geek
09 | Modifying Data Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
Implementing an Azure SQL Data Warehouse
Deploying and Configuring SSIS Packages
20761A 10: Using Subqueries Module 10   Using Subqueries.
20761A 11: Using Set Operators Module 11   Using Set Operators.
Automating SQL Server Management
Using Window Ranking, Offset, and Aggregate Functions
Sorting and Filtering Data
02 | Developing ASP.NET MVC 4 Models
Module 1 Introduction to Microsoft SQL Server 2016
04 | Using Set Operators Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
20761B 12: Using Set Operators Module 12   Using Set Operators.
Using the Set Operators
09 | Modifying Data Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
Chapter 8 Working with Databases and MySQL
Creating and Modifying Queries
Module 13: Creating Data Visualizations with Power View
CIS16 Application Programming with Visual Basic
Module 12: Implementing an Analysis Services Tabular Data Model
Module 7: Working with Measures and Measure Groups
Database systems Lecture 3 – SQL + CRUD
SQL Fundamentals in Three Hours
CIS16 Application Programming with Visual Basic
Module 3: Supporting Self Service Reporting
Access: Queries I Participation Project
Introduction To Structured Query Language (SQL)
Contents Preface I Introduction Lesson Objectives I-2
Using SQL*Plus.
Using DML to Modify Data
Manipulating Data Lesson 3.
Wings 2.0 Business Flow Reference
Shelly Cashman: Microsoft Access 2016
Module 1 Introduction to Microsoft SQL Server 2017
Designing and Implementing User- Defined Functions
Module 14: Performing Predictive Analysis with Data Mining
Module 8: Introduction to MDX Module 8 Introduction to MDX
Presentation transcript:

20761B 12: Using Set Operators Module 12   Using Set Operators

Using DELETE, DROP and TRUNCATE 20761B Module Overview 12: Using Set Operators Using BETWEEN, NOT Using DELETE, DROP and TRUNCATE  

Clause BETWEEN returns values that fall within a given range. Using BETWEEN 12: Using Set Operators Clause BETWEEN returns values that fall within a given range. SELECT * FROM HR.EMPLOYEES WHERE birthdate BETWEEN '1960.01.01' and '1970.01.01‘  

SELECT * FROM HR.EMPLOYEES WHERE NOT TitleOfCourtesy ='Dr.' 20761B Using NOT 12: Using Set Operators In order to generate the report that retrieves data from the table with the values that we don’t want to have in output we use the operator NOT.   SELECT * FROM HR.EMPLOYEES WHERE NOT TitleOfCourtesy ='Dr.'

Using the UNION Operator 20761B Using the UNION Operator 12: Using Set Operators UNION returns a result set of distinct rows combined from both input sets Duplicates are removed during query processing (affects performance) The Venn diagram uses the blue to represent rows returned from the Employees table. The blue color signifies that the query will return all records from Employees and those that also occur in Customers. Note that duplicates are filtered by UNION, regardless of which input result sets they occur in. To be filtered, duplicate data does not have to exist in both input result sets. If you are comfortable with execution plans and feel that the class won’t be too confused, consider displaying and comparing the execution plans from the UNION example in this topic and the UNION ALL example in the next one. Employees Customers -- only distinct rows from both queries are returned SELECT country, region, city FROM HR.Employees UNION SELECT country, region, city FROM Sales.Customers;

Using the UNION ALL Operator 20761B Using the UNION ALL Operator 12: Using Set Operators UNION ALL returns a result set with all rows from both input sets To avoid the performance penalty caused by filtering duplicates, use UNION ALL over UNION whenever requirements allow it   -- all rows from both queries will be returned SELECT country, region, city FROM HR.Employees UNION ALL SELECT country, region, city FROM Sales.Customers;

Using the INTERSECT Operator 20761B Using the INTERSECT Operator 12: Using Set Operators INTERSECT returns the distinct set of rows that appear in both input result sets The Venn diagram uses the darker blue color to represent rows returned from the Employees table. All rows from Employees will be returned, when they are also found in the Customers table. Employees Customers -- only rows that exist in both queries will be returned SELECT country, region, city FROM HR.Employees INTERSECT SELECT country, region, city FROM Sales.Customers;

Using the EXCEPT Operator 20761B Using the EXCEPT Operator 12: Using Set Operators EXCEPT returns only distinct rows that appear in the left set but not the right The order in which sets are specified matters The Venn diagram uses the darker color (blue) to represent rows returned from the Employees table. All rows from Employees will be returned, except those found in the Customers table. Employees Customers -- only rows from Employees will be returned SELECT country, region, city FROM HR.Employees EXCEPT SELECT country, region, city FROM Sales.Customers; http://www.essentialsql.com/wp-content/uploads/2014/10/UnionInsersectExcept.jpg

Using UPDATE to Modify Data 20761B Using UPDATE to Modify Data 7: Using DML to Modify Data UPDATE changes all rows in a table or view Unless rows are filtered with a WHERE clause or constrained with a JOIN clause Column values are changed with the SET clause   UPDATE Production.Products SET unitprice = (unitprice * 1.04) WHERE categoryid = 1 AND discontinued = 0 ; UPDATE Production.Products SET unitprice *= 1.04 -- Using compound -- assignment operators WHERE categoryid = 1 AND discontinued = 0;

Using DELETE, DROP and TRUNCATE 20761B Using DELETE, DROP and TRUNCATE 7: Using DML to Modify Data DELETE is used to delete data in the table DELETE from table Where column_name=value DROP is used to delete objects DROP table table_name TRUNCATE is used to remove all records from the object Truncate table table_name  

Demonstration: Using UNION and UNION ALL 20761B Demonstration: Using UNION and UNION ALL 12: Using Set Operators In this demonstration, you will see how to: Use UNION and UNION ALL Emphasize to students that this functionality is identical between Azure SQL Server and a locally-installed version. Preparation Steps Start the MSL-TMG1, 20761B-MIA-DC, and 20761B-MIA-SQL virtual machines. Demonstration Steps Ensure that the MSL-TMG1, 20761B-MIA-DC, and 20761B-MIA-SQL virtual machines are running, and then log on to 20761B-MIA-SQL as ADVENTUREWORKS\Student with the password Pa$$w0rd. Run D:\Demofiles\Mod12\Setup.cmd as an administrator. In the User Account Control dialog box, click Yes. At the command prompt, type y, and then press Enter. Wait for the script to finish, and then press any key. Start SQL Server Management Studio and connect to the MIA-SQL database engine instance using Windows authentication. Open the Demo.ssmssln solution in the D:\Demofiles\Mod12\Demo folder. In Solution Explorer, expand Queries, and double-click the 11 - Demonstration A.sql script file. Select the code under the comment Step 1, and then click Execute. Select the code under the comment Step 2, and then click Execute. Select the code under the comment Step 3, and then click Execute. Keep SQL Server Management Studio open for the next demonstration.

Demonstration: Using EXCEPT and INTERSECT 20761B Demonstration: Using EXCEPT and INTERSECT 12: Using Set Operators In this demonstration, you will see how to: Use UPDATE, DELETE, DROP, TRUNCATE Preparation Steps Complete the previous demonstration in this module. Demonstration Steps In Solution Explorer, open the 21 - Demonstration B.sql script file. Select the code under the comment Step 1, and then click Execute. Select the code under the comment Step 2, and then click Execute. Select the code under the comment Step 3, and then click Execute. Keep SQL Server Management Studio open for the next demonstration.