SlideShare a Scribd company logo
SQL200 SQL Programming Based on  SQL Clearly Explained  by Jan Harrington Module  1 – Relational Database Background, Basic Single Table Retrieval Operations Bookstore SQL200  Module 1
Note on SQL200 Slides These slides were originally designed to support the single SQL200 course which was used for any of MS Access, MySQL, Oracle and SQL Server. As such you may see here slides developed in any one of the above products. We are in the process of migrating the Oracle slides and the MS Access slides out into their own slide sets.  The SQL200 slides will cover MySQL and SQL Server which are virtually identical for purposes of this course. Bookstore2 SQL200  Module 2
Warning! Below are some table name changes to be aware of in doing queries. We have created synonyms so either name should work. Bookstore2 SQL200  Module 2 New Name Old Name Orders Order_filled Order_Lines Orderlines
SQL200 Contact Information Bookstore2 SQL200  Module 2 P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com [email_address]   Copyright 2001-2011. All rights reserved.
SQL200 Resources Bookstore database scripts found on box.net at http://tinyurl.com/SQLScripts   Slides can be viewed on SlideShare… http://www.slideshare.net/OCDatabases   Follow up questions? [email_address]   Bookstore SQL212  Module 1
SQL Programming Course focus is SQL language Widely used for: Database administration Enterprise application development Data driven web sites A foundation skill for eBusiness and almost all major business applications that use relational databases Bookstore SQL200  Module 1
SQL Programming A basic knowledge of query systems, perhaps via MS Access,  or some programming knowledge, is desirable We will use GUI tools or SQL Plus almost exclusively Bookstore SQL200  Module 1
Relational Database Evolution Based on Codd’s paper Early commercial efforts focused on Unix First mainframe implementation by IBM  - precursor to today’s DB2 First PC implementation in early 80’s by Oracle Bookstore SQL200  Module 1
Relational Database Basics Storage Databases Tables Rows Columns Indexes Views Cursors Application interfaces Bookstore SQL200  Module 1
Bookstore SQL200  Module 1 Relational Database Table
Constraints Database Domain Uniqueness Relationship Cardinality 1 to 1 1 to N Other Business Rule Triggers Stored Procedures Bookstore SQL200  Module 1
Bookstore SQL200  Module 1 Relational Database with constraints
Database Management Systems Bookstore SQL200  Module 1 Positioning Chart VLDB Enterprise Workgroup Single user Spreadsheet # Users Cost
System Architecture Bookstore SQL200  Module 1 Access MDB File Server  Architecture Access
System Architecture Bookstore SQL200  Module 1 Oracle DB Visual Basic App Client/Server  Architecture Access  SQL 
System Architecture Bookstore SQL200  Module 1 Oracle DB Browser Web  Architecture Web Server  SQL 
Approaching SQL Relatively simple Two main environments Interactive (This course) Embedded Static (Compiled) Dynamic Bookstore SQL200  Module 1
SQL Standardization ANSI standardization First standard in 1986 SQL 89 SQL 92 SQL 99 Various vendor extensions Microsoft/Sybase: T-SQL Oracle: PL/SQL Bookstore SQL200  Module 1
SQL Conformance Entry Intermediate Advanced Most are at least entry level Bookstore SQL200  Module 1
SQL Statements Data Manipulation Language (DML) Data Control Language (DCL) Data Definition Language (DDL) Note: SQL 99 changes these to seven types Bookstore SQL200  Module 1
SQL DDL Data definition language (DDL) Create, alter, drop, etc. Frequently implemented via various CASE tools: Visio, Embarcadero, ERWin, etc. But very useful for database administration Bookstore SQL200  Module 1
SQL DCL Data Control Language (DDL) Grant Revoke Deny Constraints Bookstore SQL200  Module 1
SQL DML Data Manipulation Language (DML) Select Insert Update Delete Bookstore SQL200  Module 1
SQL Statement Processing Bookstore SQL200  Module 1 Parse Validate Optimize Access Plan Execute
Bookstore Sample Database Before we continue (note: instructor may have already done this)… Load the sample database if you haven’t already Use Access import table feature, or Run SQL script, or Use Access upsizing wizard Bookstore SQL200  Module 1
Text Conventions In Access character strings are normally surrounded by double quotes “ Jones” In an enterprise database such as Oracle or SQL Sever enclose text strings in single quotes ‘ Jones’ Bookstore SQL200  Module 1
Date Conventions In an enterprise database such as Oracle or SQL Sever, enclose dates in single quotes ‘ 2004-12-23’ MySQL ’ 12-23-2004’ SQL Server ’ 23-DEC-04’ Oracle Bookstore SQL200  Module 1
SELECT Bookstore SQL200  Module 1 Basic Syntax ( Projection ): Select <column-list> or <*> From <table-list>
SELECT Bookstore SQL200  Module 1 Basic Example ( Projection ): select   customer_last_name,  customer_street from  customers
MS Access SQL Query Bookstore SQL200  Module 1
Bookstore SQL200  Module 1
SQL Server Query Bookstore SQL200  Module 1
SELECT with Where Clause Bookstore SQL200  Module 1 Example ( Restriction  plus   Projection ): Select <column-list> From <table-list> Where <selection-criteria>;
Comparison Operators < less than > greater than <= less than or equal to >= greater than or equal to <> or != two forms for not equal Bookstore SQL200  Module 1
SELECT with Where Bookstore SQL200  Module 1 Basic Example ( Restriction plus Projection ): select   customer_last_name,  customer_street from  customers where  customer_last_name = ‘Jones’
Select with Where Bookstore SQL200  Module 1
On Your Own Find books written by Mark Twain Show title, publisher, year Bookstore SQL200  Module 1
Complex Predicates Bookstore SQL200  Module 1 Follow normal boolean logic Select   customer_last_name,  customer_street From  customers Where  (customer_last_name = ‘Jones’ or customer_last_name = ‘Smith’)and customer_state=‘NY’
Select with Complex Where Bookstore SQL200  Module 1
Complex Where Result Bookstore SQL200  Module 1
Special Operators Can be used in where clause LIKE IN BETWEEN IS NULL Bookstore SQL200  Module 1
Like (“Wild Card Matches”) ANSI Where customer_last_name like ‘Jo%’ Like ‘Jo_’ Access Where customer_last_name like “Jo*” Like “Jo?” Bookstore SQL200  Module 1
IN Bookstore SQL200  Module 1 Select  * From  customers Where  customer_last_name in (‘Rizzo’, ‘Jones’, ‘Garcia’) The list in parentheses can be replaced by a subquery. We will study this later.
SQL Where Clause with IN Bookstore SQL200  Module 1
IS NULL Bookstore SQL200  Module 1 Select  * From  customers Where  customer_street IS NULL  SQL uses three valued logic. Must use IS NULL to test for unknowns. A null is NOT the same as blank or empty.
On Your Own Find all customers with an address not equal to 4592 Maple Lane Was Peter Johnson selected? Why or why not? Bookstore SQL200  Module 1
BETWEEN Bookstore SQL200  Module 1 Select * From orders Where order_date BETWEEN ‘1-Jan-99’ and ’31-Dec-99’ Note: date formats vary from product to product.
Where with Between Bookstore SQL200  Module 1
Removing Duplicates Bookstore SQL200  Module 1 Select DISTINCT  customer_city From  customers List once each city in which there are customers Removes duplicate rows from result set
Removing Duplicates Bookstore SQL200  Module 1
Sorting – ORDER BY Bookstore SQL200  Module 1 DESC will sort in descending order Basic syntax : Select <column list> From <table list> Where <selection criteria> Order by <column list> [DESC]
Sorting – ORDER BY Bookstore SQL200  Module 1 Select  * From  customers Order by  customer_state, customer_city Example: List all records sorted by state, city
Sorting Results with Order By Bookstore SQL200  Module 1
Selecting Top Records Bookstore SQL200  Module 1 Select Top 5 (or top 25 percent)  Customer_last_name  , contact_zip From  customers Order by customer_zip  desc ; List largest 5 zips or top 25 % of them…
SQL Exercises List all books whose publisher name begins with “H” or “T”; sort by title [hint: use LIKE] List all customers whose last name ends with “S”; sort by state, city, last name Find the order numbers of orders with order dates in 1999; sort by order #. [Hint: use BETWEEN] Find the order numbers and order dates of all orders with a “2” in column 2 of the credit card #; sort by order date descending Bookstore SQL200  Module 1 [end module]
Notes Bookstore SQL200  Module 1

More Related Content

What's hot (19)

PPTX
Sql for biggner
Arvind Kumar
 
PPT
Sql Pass Through
jrhampt
 
PPT
SQL Pass Through and the ODBC Interface
jrhampt
 
PDF
Oracle SQL Basics
Dhananjay Goel
 
PPTX
Structured Query Language (SQL)
Syed Hassan Ali
 
PPTX
New T-SQL Features in SQL Server 2012
Richie Rump
 
PDF
SQL Overview
Stewart Rogers
 
PDF
Introduction to the Structured Query Language SQL
Harmony Kwawu
 
PPTX
Introduction to SQL, SQL*Plus
Chhom Karath
 
PPT
Introduction to sql
VARSHAKUMARI49
 
PPTX
Sql basics
Genesis Omo
 
PDF
PostgreSQL Tutorial For Beginners | Edureka
Edureka!
 
PPTX
Introduction to SQL
Amin Choroomi
 
PPT
Introduction to structured query language (sql)
Sabana Maharjan
 
PDF
Android de la A a la Z XML Ulises Gonzalez
Android UNAM
 
PPT
Introduction to-sql
BG Java EE Course
 
PPT
Sql Server 2000
Om Vikram Thapa
 
PPTX
Basic SQL and History
SomeshwarMoholkar
 
PPTX
Introduction to SQL
Ehsan Hamzei
 
Sql for biggner
Arvind Kumar
 
Sql Pass Through
jrhampt
 
SQL Pass Through and the ODBC Interface
jrhampt
 
Oracle SQL Basics
Dhananjay Goel
 
Structured Query Language (SQL)
Syed Hassan Ali
 
New T-SQL Features in SQL Server 2012
Richie Rump
 
SQL Overview
Stewart Rogers
 
Introduction to the Structured Query Language SQL
Harmony Kwawu
 
Introduction to SQL, SQL*Plus
Chhom Karath
 
Introduction to sql
VARSHAKUMARI49
 
Sql basics
Genesis Omo
 
PostgreSQL Tutorial For Beginners | Edureka
Edureka!
 
Introduction to SQL
Amin Choroomi
 
Introduction to structured query language (sql)
Sabana Maharjan
 
Android de la A a la Z XML Ulises Gonzalez
Android UNAM
 
Introduction to-sql
BG Java EE Course
 
Sql Server 2000
Om Vikram Thapa
 
Basic SQL and History
SomeshwarMoholkar
 
Introduction to SQL
Ehsan Hamzei
 

Viewers also liked (20)

PPT
SQL200.2 Module 2
Dan D'Urso
 
PPT
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
Dan D'Urso
 
PDF
Using grouping sets in sql server 2008 tech republic
Kaing Menglieng
 
PPTX
Consultas en MS SQL Server 2012
CarlosFloresRoman
 
PPTX
MS SQL SERVER: Creating Views
sqlserver content
 
PDF
Sql db optimization
Nikhildas P C
 
PPS
Sql xp 04
Niit Care
 
PPT
Sql tuning guideline
Sidney Chen
 
PPTX
Statistics
Riteshkiit
 
PPT
e computer notes - Subqueries
ecomputernotes
 
PPTX
Sub-queries,Groupby and having in SQL
Vikash Sharma
 
PPSX
Locking in SQL Server
Prashant Gogoi
 
PPT
Review of SQL
Information Technology
 
RTF
Triggers-Sequences-SQL
Patrick Seery
 
PDF
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
Andriy Krayniy
 
PPT
Lecture 4. MS SQL. DML Triggers
Alexey Furmanov
 
PPTX
Sql query analyzer & maintenance
nspyrenet
 
PPT
Locking And Concurrency
sqlserver.co.il
 
PDF
SQL Server - Using Tools to Analyze Query Performance
Marek Maśko
 
SQL200.2 Module 2
Dan D'Urso
 
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
Dan D'Urso
 
Using grouping sets in sql server 2008 tech republic
Kaing Menglieng
 
Consultas en MS SQL Server 2012
CarlosFloresRoman
 
MS SQL SERVER: Creating Views
sqlserver content
 
Sql db optimization
Nikhildas P C
 
Sql xp 04
Niit Care
 
Sql tuning guideline
Sidney Chen
 
Statistics
Riteshkiit
 
e computer notes - Subqueries
ecomputernotes
 
Sub-queries,Groupby and having in SQL
Vikash Sharma
 
Locking in SQL Server
Prashant Gogoi
 
Review of SQL
Information Technology
 
Triggers-Sequences-SQL
Patrick Seery
 
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
Andriy Krayniy
 
Lecture 4. MS SQL. DML Triggers
Alexey Furmanov
 
Sql query analyzer & maintenance
nspyrenet
 
Locking And Concurrency
sqlserver.co.il
 
SQL Server - Using Tools to Analyze Query Performance
Marek Maśko
 
Ad

Similar to SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1 (20)

PPT
SQL201S Accelerated Introduction to MySQL Queries
Dan D'Urso
 
PPT
SQL302 Intermediate SQL Workshop 1
Dan D'Urso
 
PDF
SQL202 SQL Server SQL Manual
Dan D'Urso
 
PPT
SQL200.3 Module 3
Dan D'Urso
 
PDF
SQL201W MySQL SQL Manual
Dan D'Urso
 
PDF
SQL212 Oracle SQL Manual
Dan D'Urso
 
PPT
SQL212.3 Introduction to SQL using Oracle Module 3
Dan D'Urso
 
PDF
SQL302 Intermediate SQL
Dan D'Urso
 
PPT
SQL302 Intermediate SQL Workshop 2
Dan D'Urso
 
PPTX
Sql slid
pacatarpit
 
DOC
Module 3
cs19club
 
PPT
Chap 7
Karan Patil
 
PPT
Sql
jyothislides
 
PPTX
SQL Query
Imam340267
 
PPTX
SQL: Structured Query Language
Rohit Bisht
 
PDF
SQL Commands
Divyank Jindal
 
PPT
chap 7.ppt(sql).ppt
arjun431527
 
DOCX
Sql
navsissuk
 
PPTX
SQL(database)
welcometofacebook
 
PPT
[PHPUGPH] PHP Roadshow - MySQL
Cherrie Ann Domingo
 
SQL201S Accelerated Introduction to MySQL Queries
Dan D'Urso
 
SQL302 Intermediate SQL Workshop 1
Dan D'Urso
 
SQL202 SQL Server SQL Manual
Dan D'Urso
 
SQL200.3 Module 3
Dan D'Urso
 
SQL201W MySQL SQL Manual
Dan D'Urso
 
SQL212 Oracle SQL Manual
Dan D'Urso
 
SQL212.3 Introduction to SQL using Oracle Module 3
Dan D'Urso
 
SQL302 Intermediate SQL
Dan D'Urso
 
SQL302 Intermediate SQL Workshop 2
Dan D'Urso
 
Sql slid
pacatarpit
 
Module 3
cs19club
 
Chap 7
Karan Patil
 
SQL Query
Imam340267
 
SQL: Structured Query Language
Rohit Bisht
 
SQL Commands
Divyank Jindal
 
chap 7.ppt(sql).ppt
arjun431527
 
SQL(database)
welcometofacebook
 
[PHPUGPH] PHP Roadshow - MySQL
Cherrie Ann Domingo
 
Ad

More from Dan D'Urso (20)

PPT
LCD201d Database Diagramming with Lucidchart
Dan D'Urso
 
PPTX
Database Normalization
Dan D'Urso
 
PPT
VIS201d Visio Database Diagramming
Dan D'Urso
 
PPT
PRJ101a Project 2013 Accelerated
Dan D'Urso
 
PPT
PRJ101xl Project Libre Basic Training
Dan D'Urso
 
PPT
Introduction to coding using Python
Dan D'Urso
 
PPTX
Stem conference
Dan D'Urso
 
PDF
SQL200A Microsoft Access SQL Design
Dan D'Urso
 
PPTX
Microsoft access self joins
Dan D'Urso
 
PDF
AIN106 Access Reporting and Analysis
Dan D'Urso
 
PPT
SQL302 Intermediate SQL Workshop 3
Dan D'Urso
 
PDF
Course Catalog
Dan D'Urso
 
PDF
AIN100
Dan D'Urso
 
PPT
SQL206 SQL Median
Dan D'Urso
 
PDF
AIN102 Microsoft Access Queries
Dan D'Urso
 
PPT
AIN102S Access string function sample queries
Dan D'Urso
 
PPT
AIN102.2 Microsoft Access Queries
Dan D'Urso
 
PPT
AIN102.1 Microsoft Access Queries Module 1
Dan D'Urso
 
PDF
AIN100B Microsoft Access Level 2
Dan D'Urso
 
PDF
AMP110 Microsoft Access Macros
Dan D'Urso
 
LCD201d Database Diagramming with Lucidchart
Dan D'Urso
 
Database Normalization
Dan D'Urso
 
VIS201d Visio Database Diagramming
Dan D'Urso
 
PRJ101a Project 2013 Accelerated
Dan D'Urso
 
PRJ101xl Project Libre Basic Training
Dan D'Urso
 
Introduction to coding using Python
Dan D'Urso
 
Stem conference
Dan D'Urso
 
SQL200A Microsoft Access SQL Design
Dan D'Urso
 
Microsoft access self joins
Dan D'Urso
 
AIN106 Access Reporting and Analysis
Dan D'Urso
 
SQL302 Intermediate SQL Workshop 3
Dan D'Urso
 
Course Catalog
Dan D'Urso
 
AIN100
Dan D'Urso
 
SQL206 SQL Median
Dan D'Urso
 
AIN102 Microsoft Access Queries
Dan D'Urso
 
AIN102S Access string function sample queries
Dan D'Urso
 
AIN102.2 Microsoft Access Queries
Dan D'Urso
 
AIN102.1 Microsoft Access Queries Module 1
Dan D'Urso
 
AIN100B Microsoft Access Level 2
Dan D'Urso
 
AMP110 Microsoft Access Macros
Dan D'Urso
 

Recently uploaded (20)

PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PDF
Python Conference Singapore - 19 Jun 2025
ninefyi
 
PPTX
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PDF
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Open Source Milvus Vector Database v 2.6
Zilliz
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PPTX
𝙳𝚘𝚠𝚗𝚕𝚘𝚊𝚍—Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Open Source Milvus Vector Database v 2.6
Zilliz
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
𝙳𝚘𝚠𝚗𝚕𝚘𝚊𝚍—Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 

SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1

  • 1. SQL200 SQL Programming Based on SQL Clearly Explained by Jan Harrington Module 1 – Relational Database Background, Basic Single Table Retrieval Operations Bookstore SQL200 Module 1
  • 2. Note on SQL200 Slides These slides were originally designed to support the single SQL200 course which was used for any of MS Access, MySQL, Oracle and SQL Server. As such you may see here slides developed in any one of the above products. We are in the process of migrating the Oracle slides and the MS Access slides out into their own slide sets. The SQL200 slides will cover MySQL and SQL Server which are virtually identical for purposes of this course. Bookstore2 SQL200 Module 2
  • 3. Warning! Below are some table name changes to be aware of in doing queries. We have created synonyms so either name should work. Bookstore2 SQL200 Module 2 New Name Old Name Orders Order_filled Order_Lines Orderlines
  • 4. SQL200 Contact Information Bookstore2 SQL200 Module 2 P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com [email_address] Copyright 2001-2011. All rights reserved.
  • 5. SQL200 Resources Bookstore database scripts found on box.net at http://tinyurl.com/SQLScripts Slides can be viewed on SlideShare… http://www.slideshare.net/OCDatabases Follow up questions? [email_address] Bookstore SQL212 Module 1
  • 6. SQL Programming Course focus is SQL language Widely used for: Database administration Enterprise application development Data driven web sites A foundation skill for eBusiness and almost all major business applications that use relational databases Bookstore SQL200 Module 1
  • 7. SQL Programming A basic knowledge of query systems, perhaps via MS Access, or some programming knowledge, is desirable We will use GUI tools or SQL Plus almost exclusively Bookstore SQL200 Module 1
  • 8. Relational Database Evolution Based on Codd’s paper Early commercial efforts focused on Unix First mainframe implementation by IBM - precursor to today’s DB2 First PC implementation in early 80’s by Oracle Bookstore SQL200 Module 1
  • 9. Relational Database Basics Storage Databases Tables Rows Columns Indexes Views Cursors Application interfaces Bookstore SQL200 Module 1
  • 10. Bookstore SQL200 Module 1 Relational Database Table
  • 11. Constraints Database Domain Uniqueness Relationship Cardinality 1 to 1 1 to N Other Business Rule Triggers Stored Procedures Bookstore SQL200 Module 1
  • 12. Bookstore SQL200 Module 1 Relational Database with constraints
  • 13. Database Management Systems Bookstore SQL200 Module 1 Positioning Chart VLDB Enterprise Workgroup Single user Spreadsheet # Users Cost
  • 14. System Architecture Bookstore SQL200 Module 1 Access MDB File Server Architecture Access
  • 15. System Architecture Bookstore SQL200 Module 1 Oracle DB Visual Basic App Client/Server Architecture Access  SQL 
  • 16. System Architecture Bookstore SQL200 Module 1 Oracle DB Browser Web Architecture Web Server  SQL 
  • 17. Approaching SQL Relatively simple Two main environments Interactive (This course) Embedded Static (Compiled) Dynamic Bookstore SQL200 Module 1
  • 18. SQL Standardization ANSI standardization First standard in 1986 SQL 89 SQL 92 SQL 99 Various vendor extensions Microsoft/Sybase: T-SQL Oracle: PL/SQL Bookstore SQL200 Module 1
  • 19. SQL Conformance Entry Intermediate Advanced Most are at least entry level Bookstore SQL200 Module 1
  • 20. SQL Statements Data Manipulation Language (DML) Data Control Language (DCL) Data Definition Language (DDL) Note: SQL 99 changes these to seven types Bookstore SQL200 Module 1
  • 21. SQL DDL Data definition language (DDL) Create, alter, drop, etc. Frequently implemented via various CASE tools: Visio, Embarcadero, ERWin, etc. But very useful for database administration Bookstore SQL200 Module 1
  • 22. SQL DCL Data Control Language (DDL) Grant Revoke Deny Constraints Bookstore SQL200 Module 1
  • 23. SQL DML Data Manipulation Language (DML) Select Insert Update Delete Bookstore SQL200 Module 1
  • 24. SQL Statement Processing Bookstore SQL200 Module 1 Parse Validate Optimize Access Plan Execute
  • 25. Bookstore Sample Database Before we continue (note: instructor may have already done this)… Load the sample database if you haven’t already Use Access import table feature, or Run SQL script, or Use Access upsizing wizard Bookstore SQL200 Module 1
  • 26. Text Conventions In Access character strings are normally surrounded by double quotes “ Jones” In an enterprise database such as Oracle or SQL Sever enclose text strings in single quotes ‘ Jones’ Bookstore SQL200 Module 1
  • 27. Date Conventions In an enterprise database such as Oracle or SQL Sever, enclose dates in single quotes ‘ 2004-12-23’ MySQL ’ 12-23-2004’ SQL Server ’ 23-DEC-04’ Oracle Bookstore SQL200 Module 1
  • 28. SELECT Bookstore SQL200 Module 1 Basic Syntax ( Projection ): Select <column-list> or <*> From <table-list>
  • 29. SELECT Bookstore SQL200 Module 1 Basic Example ( Projection ): select customer_last_name, customer_street from customers
  • 30. MS Access SQL Query Bookstore SQL200 Module 1
  • 31. Bookstore SQL200 Module 1
  • 32. SQL Server Query Bookstore SQL200 Module 1
  • 33. SELECT with Where Clause Bookstore SQL200 Module 1 Example ( Restriction plus Projection ): Select <column-list> From <table-list> Where <selection-criteria>;
  • 34. Comparison Operators < less than > greater than <= less than or equal to >= greater than or equal to <> or != two forms for not equal Bookstore SQL200 Module 1
  • 35. SELECT with Where Bookstore SQL200 Module 1 Basic Example ( Restriction plus Projection ): select customer_last_name, customer_street from customers where customer_last_name = ‘Jones’
  • 36. Select with Where Bookstore SQL200 Module 1
  • 37. On Your Own Find books written by Mark Twain Show title, publisher, year Bookstore SQL200 Module 1
  • 38. Complex Predicates Bookstore SQL200 Module 1 Follow normal boolean logic Select customer_last_name, customer_street From customers Where (customer_last_name = ‘Jones’ or customer_last_name = ‘Smith’)and customer_state=‘NY’
  • 39. Select with Complex Where Bookstore SQL200 Module 1
  • 40. Complex Where Result Bookstore SQL200 Module 1
  • 41. Special Operators Can be used in where clause LIKE IN BETWEEN IS NULL Bookstore SQL200 Module 1
  • 42. Like (“Wild Card Matches”) ANSI Where customer_last_name like ‘Jo%’ Like ‘Jo_’ Access Where customer_last_name like “Jo*” Like “Jo?” Bookstore SQL200 Module 1
  • 43. IN Bookstore SQL200 Module 1 Select * From customers Where customer_last_name in (‘Rizzo’, ‘Jones’, ‘Garcia’) The list in parentheses can be replaced by a subquery. We will study this later.
  • 44. SQL Where Clause with IN Bookstore SQL200 Module 1
  • 45. IS NULL Bookstore SQL200 Module 1 Select * From customers Where customer_street IS NULL SQL uses three valued logic. Must use IS NULL to test for unknowns. A null is NOT the same as blank or empty.
  • 46. On Your Own Find all customers with an address not equal to 4592 Maple Lane Was Peter Johnson selected? Why or why not? Bookstore SQL200 Module 1
  • 47. BETWEEN Bookstore SQL200 Module 1 Select * From orders Where order_date BETWEEN ‘1-Jan-99’ and ’31-Dec-99’ Note: date formats vary from product to product.
  • 48. Where with Between Bookstore SQL200 Module 1
  • 49. Removing Duplicates Bookstore SQL200 Module 1 Select DISTINCT customer_city From customers List once each city in which there are customers Removes duplicate rows from result set
  • 50. Removing Duplicates Bookstore SQL200 Module 1
  • 51. Sorting – ORDER BY Bookstore SQL200 Module 1 DESC will sort in descending order Basic syntax : Select <column list> From <table list> Where <selection criteria> Order by <column list> [DESC]
  • 52. Sorting – ORDER BY Bookstore SQL200 Module 1 Select * From customers Order by customer_state, customer_city Example: List all records sorted by state, city
  • 53. Sorting Results with Order By Bookstore SQL200 Module 1
  • 54. Selecting Top Records Bookstore SQL200 Module 1 Select Top 5 (or top 25 percent) Customer_last_name , contact_zip From customers Order by customer_zip desc ; List largest 5 zips or top 25 % of them…
  • 55. SQL Exercises List all books whose publisher name begins with “H” or “T”; sort by title [hint: use LIKE] List all customers whose last name ends with “S”; sort by state, city, last name Find the order numbers of orders with order dates in 1999; sort by order #. [Hint: use BETWEEN] Find the order numbers and order dates of all orders with a “2” in column 2 of the credit card #; sort by order date descending Bookstore SQL200 Module 1 [end module]