Successfully reported this slideshow.

Learning SQL

0

Share

Loading in …3
×
1 of 20
1 of 20

Learning SQL

0

Share

Download to read offline

Description

Presented at PhillyDB
http://www.meetup.com/PhillyDB/events/36532262/

Transcript

  1. 1. Beginning SQL Sean Collins
  2. 2. Lesson Plan Theory Relational Algebra & Sets Practice SQL SQLite Self-Directed Learning
  3. 3. Theory Set Theory The branch of mathematics that deals with the formal properties of sets as units (without regard to the nature of their individual constituents) and the expression of other branches of mathematics in terms of sets
  4. 4. Examples Union Intersection Set-Difference
  5. 5. Union
  6. 6. Intersection
  7. 7. Set-Difference
  8. 8. Why This Is Important A whole branch of mathematics that deals with collections of items and operations. SQL is just one of many ways to describe collections of items and operations. Learning to think about data as discrete sets of items opens new possibilities, because you are given new operations to manipulate sets.
  9. 9. SQL Structured Query Language SQL is a language standard Different databases products have extra features tacked on to the language Understand the structure of the language Everything else is just syntax
  10. 10. SQLite Free and Open Source relational database LIBRARY Most SQL products are considered a “RDBMS” Relational Database Management System Which means they contain extra functionality Networking Backups Authentication Etc....
  11. 11. Things We Don’t Care About. All We Want Is SQL.
  12. 12. The SQL Data Model Data in an SQL database Tables Columns Rows
  13. 13. Tables Tables are the “sets” of discourse in SQL Tables contain data of the same type. Customers in a Customer table Orders in an Order table
  14. 14. Theory To Practice Pull up all of our customers, and their orders. UNION Pull up all of our customers who have ever ordered something INTERSECTION
  15. 15. Columns Tables contain columns Columns can have different data types Dates Timestamps Integers Currency
  16. 16. Digression: Keys Most data has a unique identifier, somewhere People: Social Security Numbers Groceries: UPC/Barcodes Cars: VIN SQL has a data type to give hints to the database engine about these unique identifiers
  17. 17. Keys Typically a table will have a PRIMARY KEY Often, it is a automatically incremented integer Blog post #1 Blog post #2 ....
  18. 18. Connecting Tables (Relations) Two tables can be related through the use of FOREIGN KEYS Customer table has a primary key (customer_id) Order table has a primary key (order_id) and a column (customer) that references the customer table. The SQL database now knows about this relation.
  19. 19. Foreign Keys & Referential Integrity Foreign keys are used to enforce REFERENTIAL INTEGRITY You cannot have an order for a customer that doesn’t exist. You cannot delete a customer unless you also delete their orders.
  20. 20. SQLite Example We will now go through a hands-on exercise with SQLite and the sample database from GitHub A more complete example database can be found on the Chinook Project: http://chinookdatabase.codeplex.com/ This is listed in Lesson_04.md of the GitHub project

Editor's Notes

  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Description

    Presented at PhillyDB
    http://www.meetup.com/PhillyDB/events/36532262/

    Transcript

    1. 1. Beginning SQL Sean Collins
    2. 2. Lesson Plan Theory Relational Algebra & Sets Practice SQL SQLite Self-Directed Learning
    3. 3. Theory Set Theory The branch of mathematics that deals with the formal properties of sets as units (without regard to the nature of their individual constituents) and the expression of other branches of mathematics in terms of sets
    4. 4. Examples Union Intersection Set-Difference
    5. 5. Union
    6. 6. Intersection
    7. 7. Set-Difference
    8. 8. Why This Is Important A whole branch of mathematics that deals with collections of items and operations. SQL is just one of many ways to describe collections of items and operations. Learning to think about data as discrete sets of items opens new possibilities, because you are given new operations to manipulate sets.
    9. 9. SQL Structured Query Language SQL is a language standard Different databases products have extra features tacked on to the language Understand the structure of the language Everything else is just syntax
    10. 10. SQLite Free and Open Source relational database LIBRARY Most SQL products are considered a “RDBMS” Relational Database Management System Which means they contain extra functionality Networking Backups Authentication Etc....
    11. 11. Things We Don’t Care About. All We Want Is SQL.
    12. 12. The SQL Data Model Data in an SQL database Tables Columns Rows
    13. 13. Tables Tables are the “sets” of discourse in SQL Tables contain data of the same type. Customers in a Customer table Orders in an Order table
    14. 14. Theory To Practice Pull up all of our customers, and their orders. UNION Pull up all of our customers who have ever ordered something INTERSECTION
    15. 15. Columns Tables contain columns Columns can have different data types Dates Timestamps Integers Currency
    16. 16. Digression: Keys Most data has a unique identifier, somewhere People: Social Security Numbers Groceries: UPC/Barcodes Cars: VIN SQL has a data type to give hints to the database engine about these unique identifiers
    17. 17. Keys Typically a table will have a PRIMARY KEY Often, it is a automatically incremented integer Blog post #1 Blog post #2 ....
    18. 18. Connecting Tables (Relations) Two tables can be related through the use of FOREIGN KEYS Customer table has a primary key (customer_id) Order table has a primary key (order_id) and a column (customer) that references the customer table. The SQL database now knows about this relation.
    19. 19. Foreign Keys & Referential Integrity Foreign keys are used to enforce REFERENTIAL INTEGRITY You cannot have an order for a customer that doesn’t exist. You cannot delete a customer unless you also delete their orders.
    20. 20. SQLite Example We will now go through a hands-on exercise with SQLite and the sample database from GitHub A more complete example database can be found on the Chinook Project: http://chinookdatabase.codeplex.com/ This is listed in Lesson_04.md of the GitHub project

    Editor's Notes

  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • More Related Content

    Related Books

    Free with a 30 day trial from Scribd

    See all

    ×