Your SlideShare is downloading. ×
SQL200.1 Module 1
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

SQL200.1 Module 1

633
views

Published on

Introduction to SQL Module 1.

Introduction to SQL Module 1.

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
633
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. SQL200 Based on SQL Clearly Explained by Jan Harrington SQL Programming Module 1 – Relational Database Background, Basic Single Table Retrieval Operations
  • 2. SQL200 P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com [email_address]
  • 3. 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
  • 4. SQL Programming
    • A basic knowledge of query systems, perhaps via MS Access, or some programming knowledge, is desirable
    • We will use GUI tools or Access “SQL View” almost exclusively
  • 5. 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
  • 6. Relational Database Basics
    • Storage
    • Databases
    • Tables
    • Rows
    • Columns
    • Indexes
    • Views
    • Cursors
    • Application interfaces
  • 7. Relational Database Table
  • 8. Constraints
    • Database
      • Domain
      • Uniqueness
      • Relationship Cardinality
        • 1 to 1
        • 1 to N
    • Other Business Rule
      • Triggers
      • Stored Procedures
  • 9. Relational Database with constraints
  • 10. Database Management Systems Positioning Chart VLDB Enterprise Workgroup Single user Spreadsheet # Users Cost
  • 11. System Architecture Access MDB File Server Architecture Access
  • 12. System Architecture Oracle DB Visual Basic App Client/Server Architecture Access  SQL 
  • 13. System Architecture Oracle DB Browser Web Architecture Web Server  SQL 
  • 14. Approaching SQL
    • Relatively simple
    • Two main environments
      • Interactive (This course)
      • Embedded
        • Static (Compiled)
        • Dynamic
  • 15. SQL Standardization
    • ANSI standardization
      • First standard in 1986
      • SQL 89
      • SQL 92
      • SQL 99
    • Various vendor extensions
      • Microsoft/Sybase: T-SQL
      • Oracle: PL/SQL
  • 16. SQL Conformance
    • Entry
    • Intermediate
    • Advanced
    • Most are at least entry level
  • 17. SQL Statements
    • Data Manipulation Language (DML)
    • Data Control Language (DCL)
    • Data Definition Language (DDL)
    • Note: SQL 99 changes these to seven types
  • 18. 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
  • 19. SQL DCL
    • Data Control Language (DDL)
      • Grant
      • Revoke
      • Constraints
  • 20. SQL DML
    • Data Manipulation Language (DML)
      • Select
      • Insert
      • Update
      • Delete
  • 21. SQL Statement Processing Parse Validate Optimize Access Plan Execute
  • 22. 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
  • 23. Text Conventions
    • In Access character strings are normally surrounded by double quotes
      • “ Jones”
    • In an enterprise database such as Oracle or SQL Sever, then single quotes
      • ‘ Jones’
    • Be sensitive to the environment of your class in copying scripts from the PowerPoint slides!
  • 24. Date Conventions
    • In Access date are normally surrounded by pound signs
      • #12/23/2004#
    • In an enterprise database such as Oracle or SQL Sever, then single quotes
      • ‘ 2004-12-23’ MySQL
      • ’ 12-23-2004’ SQL Server
      • ’ 23-DEC-04’ Oracle
    • Be sensitive to the environment of your class in copying scripts from the PowerPoint slides!
  • 25. SELECT Basic Syntax ( Projection ): Select <column-list> or <*> From <table-list>
  • 26. SELECT Basic Example ( Projection ): select customer_last_name, customer_street from customers
  • 27. MS Access SQL Query
  • 28.  
  • 29. SQL Server Query
  • 30. SELECT with Where Clause Example ( Restriction plus Projection ): Select <column-list> From <table-list> Where <selection-criteria>;
  • 31. SELECT with Where Basic Example ( Restriction plus Projection ): select customer_last_name, customer_street from customers where customer_last_name = “Jones”
  • 32. Select with Where
  • 33. On Your Own
    • Find books written by Mark Twain
    • Show title, publisher, year
  • 34. Complex Predicates 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’
  • 35. Select with Complex Where
  • 36. Complex Where Result
  • 37. Special Operators
    • Can be used in where clause
    • LIKE
    • IN
    • BETWEEN
    • IS NULL
  • 38. Like (“Wild Card Matches”)
    • ANSI
    • Where customer_last_name like “Jo%”
    • Like “Jo_”
    • Access
    • Where customer_last_name like “Jo*”
    • Like “Jo?”
  • 39. IN 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.
  • 40. SQL Where Clause with IN
  • 41. IS NULL 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.
  • 42. On Your Own
    • Find all customers with an address not equal to 4592 Maple Lane
    • Was Peter Johnson selected?
    • Why or why not?
  • 43. BETWEEN Select * From orders Where order_date BETWEEN #1/1/99# and #12/31/99# Note: date formats vary from product to product. Above is Access syntax, SQL Server uses single quotes. Ex: ‘1/1/99’
  • 44. Where with Between
  • 45. Removing Duplicates Select DISTINCT customer_city From customers List once each city in which there are customers Removes duplicate rows from result set
  • 46. Removing Duplicates
  • 47. Sorting – ORDER BY DESC will sort in descending order Basic syntax : Select <column list> From <table list> Where <selection criteria> Order by <column list> [DESC]
  • 48. Sorting – ORDER BY Select * From customers Order by customer_state, customer_city Example: List all records sorted by state, city
  • 49. Sorting Results with Order By
  • 50. Selecting Top Records 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…
  • 51. 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
    [end module]