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)

PDF
SQL200A Microsoft Access SQL Design
Dan D'Urso
 
PPT
SQL200.3 Module 3
Dan D'Urso
 
PPT
SQL201S Accelerated Introduction to MySQL Queries
Dan D'Urso
 
PPTX
introduction to SQL query language beginner.ppt
PatriceRochon1
 
PPTX
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
PDF
Sql
Atul Pant
 
PPT
Migrate Microsoft Access to SQL Server
ADNUG
 
DOCX
DBMS
Karan Thakkar
 
PDF
Sql2008 (1)
YanivGupta
 
PPT
Module02
Sridhar P
 
PPTX
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
PPTX
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
PDF
Database Systems Design Implementation and Management 11th Edition Coronel So...
qyvnrll170
 
PDF
Mastering Oracle SQL & SQL*Plus for Beginners,
samirben82
 
PDF
Sq lite module5
Highervista
 
PPTX
Introduction to Database SQL & PL/SQL
Collaboration Technologies
 
PPTX
SQL OVERVIEW for a new introduced student.pptx
JosephNhlane
 
PPTX
CSE311_IAH_Slide06_SQL _Retrival_Queries.pptx
noshinnawar31
 
PDF
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
MariaDB plc
 
SQL200A Microsoft Access SQL Design
Dan D'Urso
 
SQL200.3 Module 3
Dan D'Urso
 
SQL201S Accelerated Introduction to MySQL Queries
Dan D'Urso
 
introduction to SQL query language beginner.ppt
PatriceRochon1
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
Migrate Microsoft Access to SQL Server
ADNUG
 
Sql2008 (1)
YanivGupta
 
Module02
Sridhar P
 
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
Database Systems Design Implementation and Management 11th Edition Coronel So...
qyvnrll170
 
Mastering Oracle SQL & SQL*Plus for Beginners,
samirben82
 
Sq lite module5
Highervista
 
Introduction to Database SQL & PL/SQL
Collaboration Technologies
 
SQL OVERVIEW for a new introduced student.pptx
JosephNhlane
 
CSE311_IAH_Slide06_SQL _Retrival_Queries.pptx
noshinnawar31
 
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
MariaDB plc
 
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
 
PPTX
Microsoft access self joins
Dan D'Urso
 
PDF
SQL302 Intermediate SQL
Dan D'Urso
 
PDF
AIN106 Access Reporting and Analysis
Dan D'Urso
 
PPT
SQL302 Intermediate SQL Workshop 3
Dan D'Urso
 
PPT
SQL302 Intermediate SQL Workshop 2
Dan D'Urso
 
PDF
Course Catalog
Dan D'Urso
 
PPT
SQL302 Intermediate SQL Workshop 1
Dan D'Urso
 
PDF
SQL212 Oracle SQL Manual
Dan D'Urso
 
PDF
SQL201W MySQL SQL Manual
Dan D'Urso
 
PDF
AIN100
Dan D'Urso
 
PPT
SQL206 SQL Median
Dan D'Urso
 
PDF
SQL202 SQL Server SQL Manual
Dan D'Urso
 
PDF
AIN102 Microsoft Access Queries
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
 
Microsoft access self joins
Dan D'Urso
 
SQL302 Intermediate SQL
Dan D'Urso
 
AIN106 Access Reporting and Analysis
Dan D'Urso
 
SQL302 Intermediate SQL Workshop 3
Dan D'Urso
 
SQL302 Intermediate SQL Workshop 2
Dan D'Urso
 
Course Catalog
Dan D'Urso
 
SQL302 Intermediate SQL Workshop 1
Dan D'Urso
 
SQL212 Oracle SQL Manual
Dan D'Urso
 
SQL201W MySQL SQL Manual
Dan D'Urso
 
AIN100
Dan D'Urso
 
SQL206 SQL Median
Dan D'Urso
 
SQL202 SQL Server SQL Manual
Dan D'Urso
 
AIN102 Microsoft Access Queries
Dan D'Urso
 

Recently uploaded (20)

PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Biography of Daniel Podor.pdf
Daniel Podor
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 

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]