Chapter 10 Queries and Updating Part C. SQL Copyright 2005 Radian Publishing Co.

Slides:



Advertisements
Similar presentations
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
Advertisements

Introduction to Oracle9i: SQL1 Basic SQL SELECT Statements.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Structured Query Language Part I Chapter Three CIS 218.
Introduction to Structured Query Language (SQL)
Microsoft Access 2010 Chapter 7 Using SQL.
Chapter 2 Basic SQL SELECT Statements
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
ASP.NET Programming with C# and SQL Server First Edition
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
Using SQL Queries to Insert, Update, Delete, and View Data Date Retrieval from a single table & Calculations © Abdou Illia MIS Spring 2015.
Chapter 2 Basic SQL SELECT Statements Oracle 10g: SQL.
Chapter 3 Single-Table Queries
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
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.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
SQL Training SQL Statements – Part 1. Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. Lesson Objectives Explain the role of SQL.
SQL/lesson 2/Slide 1 of 45 Retrieving Result Sets Objectives In this lesson, you will learn to: * Use wildcards * Use the IS NULL and IS NOT NULL keywords.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Lecture6:Data Manipulation in SQL, Simple SQL queries Prepared by L. Nouf Almujally Ref. Chapter5 Lecture6 1.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Using Special Operators (LIKE and IN)
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 13 Subqueries and Views Part C. SQL Copyright 2005 Radian Publishing Co.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Chapter 11 Functions and Groups Part C. SQL Copyright 2005 Radian Publishing Co.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 22 - SQL, MySQL, DBI and ADO Outline 22.1 Introduction 22.2 Relational Database Model 22.3 Relational.
IS6146 Databases for Management Information Systems Lecture 1: Introduction to IS6146 Rob Gleasure robgleasure.com.
Selecting Data Database Administration Fundamentals LESSON 3.1a.
1 Chapter 2 Basic SQL SELECT Statements. 2 Chapter Objectives Distinguish between an RDBMS and an ORDBMS Identify keywords, mandatory clauses, and optional.
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
Lecture3b - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data Guide to Oracle 10g ITBIS373 Database Development.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
2 Delete and update  Delete a record  Update a record DELETE FROM vet_appt WHERE vet_appt_id = 3; UPDATE animal SET’ gender = “MS” WHERE animal_id =
Tarik Booker CS 122. What we will cover… Tables (review) SELECT statement DISTINCT, Calculated Columns FROM Single tables (for now…) WHERE Date clauses,
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Query Methods Simple SQL Statements Start ….
SQL Query Getting to the data ……..
Chapter 5 Introduction to SQL.
Query Methods Where Clauses Start ….
Query Methods Where Clauses Start ….
 2012 Pearson Education, Inc. All rights reserved.
Chapter 9 SQL and RDBMS Part C. SQL
PHP + MySQL Commands Refresher.
SQL Tutorial.
Chapter 8 Working with Databases and MySQL
Chapter 11 Functions and Groups
CIS16 Application Programming with Visual Basic
Chapter 22 - SQL, MySQL, DBI and ADO
Chapter 13 Subqueries and Views
HAVING,INDEX,COMMIT & ROLLBACK
Introduction To Structured Query Language (SQL)
Lesson 3 Chapter 10.
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

Chapter 10 Queries and Updating Part C. SQL Copyright 2005 Radian Publishing Co.

2/28 Contents Chapter 10 Queries and Updating 10.1 Simple Query 10.1 A. Select * 10.1 B. Selecting Individual Columns10.1 B. Selecting Individual Columns 10.1 C. Queries with Distinction 10.1 D. Ordering the Result 10.1 E. Efficiency Issue with Order 10.1 F. Specifying Alias for Column10.1 F. Specifying Alias for Column 10.1 G. Simple Expressions in Query10.1 G. Simple Expressions in Query 10.2 The WHERE Clause 10.2 A. Using Logical Operators 10.2 B. The IN Operator 10.2 C. The BETWEEN … AND Operator10.2 C. The BETWEEN … AND Operator 10.2 D. The LIKE Operator 10.3 Exporting the Query Results 10.3 A. Outputting as a New Table 10.3 B. Outputting as a a Text File 10.4 Updating and Deleting Records 10.4 A. The SQL UPDATE 10.4 B. The SQL DELETE

Copyright 2005 Radian Publishing Co.3/28 Chapter 10 Queries and Updating In this chapter, you will learn how to query the data contained in tables using the SQL SELECT command. You will also learn how to update and delete records using SQL UPDATE and DELETE commands.

Copyright 2005 Radian Publishing Co.4/ Simple Query A query is a simple request to retrieve information from a database using criteria.

Copyright 2005 Radian Publishing Co.5/ A. Select * (1/3) In SELECT *, the asterisk is a wildcard character that tells DBMS to return all the fields.

Copyright 2005 Radian Publishing Co.6/ A. Select * (2/3)

Copyright 2005 Radian Publishing Co.7/ A. Select * (3/3) A cursor is the result of a query. It is a read-only table available for browsing, reporting or input to application programs. It is temporary as it will be removed when the application is closed.

Copyright 2005 Radian Publishing Co.8/ B. Selecting Individual Columns The SQL command allows you to display any columns you want. SELECT FieldNames FROM TableName;

Copyright 2005 Radian Publishing Co.9/ C. Queries with Distinction The keyword DISTINCT is used to remove duplicate records in the query result. SELECT DISTINCT FieldNames FROM TableName;

Copyright 2005 Radian Publishing Co.10/ D. Ordering the Result (1/2) The basic syntax for ordering the result is SELECT [DISTINCT] FieldNames FROM TableName ORDER BY FieldName1, FieldName2 ¡K [ASC|DESC]

Copyright 2005 Radian Publishing Co.11/ D. Ordering the Result (2/2)

Copyright 2005 Radian Publishing Co.12/ E. Efficiency Issue with Order The efficiency of ordering can be improved by creating indexes. If a certain ordering is frequently needed, an index should be created for this ordering.

Copyright 2005 Radian Publishing Co.13/ F. Specifying Alias for Column (1/2) A column alias can provide more descriptive names for columns. For MySQL and Visual FoxPro, alias can be used in references in the ORDER BY and GROUP BY clauses, but this is not allowed in MS Access.

Copyright 2005 Radian Publishing Co.14/ F. Specifying Alias for Column (2/2)

Copyright 2005 Radian Publishing Co.15/ G. Simple Expressions in Query A query may consist of expressions instead of field names in the SELECT clause.

Copyright 2005 Radian Publishing Co.16/ The WHERE Clause The syntax of a SELECT statement with a WHERE clause is SELECT [DISTINCT] SelectItems FROM TableName WHERE Conditions ORDER BY OrderItem1 [, OrderItem2 ] ; Alias is not allowed in the WHERE clause for all DBMS. An exact match is required for both MySQL and MS Access, but not for Visual FoxPro. (Note: All the DBMS mentioned in the textbook are not case-sensitive. )

Copyright 2005 Radian Publishing Co.17/ A. Using Logical Operators Logical operators, AND, OR and NOT, are used in the WHERE clause.

Copyright 2005 Radian Publishing Co.18/ B. The IN Operator The IN operator returns true if the specified data matches any one of the elements in the given set.

Copyright 2005 Radian Publishing Co.19/ C. The BETWEEN … AND Operator The BETWEEN … AND operator returns true if the specified data falls between a starting value and an ending value inclusively.

Copyright 2005 Radian Publishing Co.20/ D. The LIKE Operator (1/2) The LIKE operator compares the skeletons of two strings. The wildcard (_) means any single character in the position. The wildcard (%) means any string in forming the skeleton.

Copyright 2005 Radian Publishing Co.21/ D. The LIKE Operator (2/2)

Copyright 2005 Radian Publishing Co.22/ Exporting the Query Results Since the result of a query will be lost when the application is closed, sometimes, you might want to store the results. Fig.10.2 Variations between DBMS in exporting query results

Copyright 2005 Radian Publishing Co.23/ A. Outputting as a New Table In MS Access, the syntax to output the query as a table is: SELECT [DISTINCT] SelectItems INTO OutTable FROM TableName... In MySQL, the syntax to output the query as a table is: CREATE TABLE OutTable SELECT SelectItems FROM TableName... In Visual FoxPro, the syntax to output the query as a table is: SELECT [DISTINCT] SelectItems INTO TABLE OutTable FROM TableName...

Copyright 2005 Radian Publishing Co.24/ B. Outputting as a a Text File In MySQL, the syntax to output the query result to a text file is: SELECT SelectItems INTO OUTFILE 'FileName' FROM TableName... In Visual FoxPro, the syntax to output the query result to a text file is: SELECT SelectItems TO FILE 'FileName' FROM TableName...

Copyright 2005 Radian Publishing Co.25/ A. The SQL UPDATE (1/2) The basic syntax for updating a set of records is UPDATE TableName SET FieldName1 = Expression1 [, FieldName2 = Expression2 ] WHERE Conditions;

Copyright 2005 Radian Publishing Co.26/ A. The SQL UPDATE (2/2)

Copyright 2005 Radian Publishing Co.27/ B. The SQL DELETE (1/2) The basic syntax for deleting a set of records is DELETE FROM TableName WHERE Conditions; If the WHERE clause is missed, all records will be deleted.

Copyright 2005 Radian Publishing Co.28/ B. The SQL DELETE (2/2) Delete those records with quantity less than 5 Delete all records