WebFund 2014W Lecture 7: Difference between revisions

From Soma-notes
Created page with "The video from the lecture given on January 29, 2014 is available: * [http://www.screencast.com/t/5lpc5qWqGBU2 Small from screencast.com] * [http://www.screencast.com/t/x2iAx5..."
 
Leah (talk | contribs)
No edit summary
Line 3: Line 3:
* [http://www.screencast.com/t/x2iAx5KDyj Large from screencast.com]
* [http://www.screencast.com/t/x2iAx5KDyj Large from screencast.com]
* [http://dl.cuol.ca/capture/Anil.Somayaji/COMP_2406_2014W_Lecture_7_-_20140129_143752_27.mp4 Original from CUOL]
* [http://dl.cuol.ca/capture/Anil.Somayaji/COMP_2406_2014W_Lecture_7_-_20140129_143752_27.mp4 Original from CUOL]
Databases:
why?
* Persistence - You want to stick around (vs. RAM)
* Concurrency in writes - (vs. files)
* Search - (vs. files)
** Dynamic data should NOT be stored in files.
SQL(Structured Query Language) vs. NoSQL
* SQL makes queries to databases, assuming queries are highly structured.
* for relational databases.
What is a structure of a relational database?
e.g. Tables - relations connect fields between tables
* rows (records)
* columns (fields)
Example
=====
Table: People
ID    First Name      Last Name      Phone                  Email 
1      Anil                Somayaji        555-1212          soma@scs.carleton.ca
2      Dana              Somayaji        555-1212          dana@example.ca (should check whether it is a valid address)
Validation Problem:
* Where to check for bad data?
* Can do on:
** Web client (helpful)
** Web server (must)
** Database (useful)
Example continued:
Table: Invoices
Inv. ID    Description      Amount      Customer
1            iPad                $700          1  <- Which is Anil in the People table)
2
* One relation: Invoice = Customer ID -> People ID
Could ask for simple queries:
* All records in People with first name == Anil
* Which customer has spent the most in our store?
** Sum of all invoices for each customer
** find max
Indexing:
* Simplest: sorts specific fields in a table (create secondary keys)
                          Secondary key          Primary key
                          ========            =======
                          First Name                ID
                          ---------                --
>>                      Anil                          1
sort                    Dana                        2
these                  Annie                        3
alphabetically
Transactions:
* What if I want to change records in multiple tables in a coordinated fashion?
* Airline example
** Reserve seat
** Pay
** Commit: check that payment and reservation both worked first
NoSQL Databases: No transactions, no real relations

Revision as of 16:55, 13 March 2014

The video from the lecture given on January 29, 2014 is available:

Databases: why?

  • Persistence - You want to stick around (vs. RAM)
  • Concurrency in writes - (vs. files)
  • Search - (vs. files)
    • Dynamic data should NOT be stored in files.

SQL(Structured Query Language) vs. NoSQL

  • SQL makes queries to databases, assuming queries are highly structured.
  • for relational databases.

What is a structure of a relational database? e.g. Tables - relations connect fields between tables

  • rows (records)
  • columns (fields)

Example

=

Table: People

ID First Name Last Name Phone Email 1 Anil Somayaji 555-1212 soma@scs.carleton.ca 2 Dana Somayaji 555-1212 dana@example.ca (should check whether it is a valid address)

Validation Problem:

  • Where to check for bad data?
  • Can do on:
    • Web client (helpful)
    • Web server (must)
    • Database (useful)

Example continued:

Table: Invoices

Inv. ID Description Amount Customer 1 iPad $700 1 <- Which is Anil in the People table) 2

  • One relation: Invoice = Customer ID -> People ID

Could ask for simple queries:

  • All records in People with first name == Anil
  • Which customer has spent the most in our store?
    • Sum of all invoices for each customer
    • find max

Indexing:

  • Simplest: sorts specific fields in a table (create secondary keys)
                         Secondary key           Primary key
                         ========             =======
                          First Name                 ID
                          ---------                 --

>> Anil 1 sort Dana 2 these Annie 3 alphabetically

Transactions:

  • What if I want to change records in multiple tables in a coordinated fashion?
  • Airline example
    • Reserve seat
    • Pay
    • Commit: check that payment and reservation both worked first

NoSQL Databases: No transactions, no real relations