1 / 7

Web Database Programming Week 9

Web Database Programming Week 9. DB Administration – Multiple Tables. Table Relationships. One to many Use foreign key at the Many side of the relationship E.g. pets & species Many to many Use an extra relational table This table contains foreign keys for Both sides of relationship

Download Presentation

Web Database Programming Week 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web Database Programming Week 9 DB Administration – Multiple Tables

  2. Table Relationships • One to many • Use foreign key at the Many side of the relationship • E.g. pets & species • Many to many • Use an extra relational table • This table contains foreign keys for Both sides of relationship • E.g. pets ownership table captures relationship between pets & owners

  3. Display Table w/ Foreign Keys (FKs) • Need to join the table(s) containing FKs with the table(s) providing FKs • Must specify key relationships in join SELECT ownership.id, owners.lastname, pets.name FROM ownership, owners, pets WHERE ownership.ownerId = owners.id AND ownership.petId = pets.id

  4. Rows Aggregation • GROUP BY clause • Rows with the same value will be grouped together • Enable the use of aggregation functions SELECT city from customer GROUP BY city;

  5. Aggregation Functions • Count() • Sum() • Min() • Max() • Avg() SELECT city, COUNT(*) from customer GROUP BY city;

  6. Example • Pet Ownership Administration: • Create an ownership • Update an ownership • Delete an ownership • Summary report • E.g. a table listing the number of pets owned by each owner

  7. Additional SQL Criteria for WHERE Clause • Direct comparison: =, <>, <=, <, >, >= • Existence: IS NULL, IS NOT NULL • Between WHERE aNumber BETWEEN 234 AND 999 • Combining: AND, ORWHERE (LastName = ‘Smith’ AND FirstName = ‘Jack’) OR (LastName = ‘Jones’ AND FirstName = ‘Kim’) • Negation: WHERE NOT( LastName >= ‘Jones’) • Set membership: WHERE LastName In (‘Jones’, ‘Smith’,‘$formValue’) • Like: WHERE LastName LIKE ‘Johns[oe]n’WHERE LastName LIKE ‘Ben%’

More Related