MySQL, SQL and phpMyAdmin

Homework

  1. SQL Syntax
  2. Relational Databases
  3. phpMyAdmin
  4. MySQL with PHP and phpMyAdmin

Morning reflection

  • Initial comments on 262 Assignment 4
    • frontend vs backend javascript
    • HTML vs JSON endpoints
    • simplifying routes

Housekeeping


1. Relational Data Models

Learning Objectives

  • Define the features of a relational data model.
  • Understand how to read and diagram a data model using and Entity Relationship Diagram (ERD).
  • Demonstrate common relationships found in relational data models:
    • One-to-many
    • Many-to-many
  • Define normalization
  • Summarize the similarities and differences between MySQL and MariaDB.

Materials

Key Takeaways

  • Naming convensions for database tables and columns:
    • lowercase
    • spaces replaced with underscores
    • no numbers
    • valid, descriptive names no longer than 64 characters

2. phpMyAdmin Tour

Learning Objectives

  • Perform common operations using the phpMyAdmin control panel:
    • Create a database.
    • Define a table.
    • Insert data into a table.
    • Perform SQL queries against a database.

Materials

Key Takeaways

  • Changing the structure of a database can be difficult after you insert data. Getting it right the first (or second) time can be difficult and the reason NoSQL databases are popular.
  • It’s important to not forget your constraints. A key concept of relational data models is maintaining data integrity.

3. SQL Queries

Learning Objectives

  • Understand the syntax of common SQL queries.
  • Perform common CRUD operations on a database using SQL.
    • Create a record with INSERT.
    • Retrieve a record with SELECT.
      • Filter results with WHERE conditions.
      • Sort results with an ORDER clause.
    • Update a record with UPDATE.
      • Target records with WHERE conditions.
    • Combine the results from two tables with INNER JOIN.
  • Define a mysql function.

Terminology

Materials

Key Takeaways

  • Comparisons use =, not == or ===.
  • Inserting data using phpMyAdmin can be a pain. You will often create an import script instead. This can be done with your language of choice.
  • We rarely delete records in industry. Instead, there will usually be an active field (or similar) that is set to yes or no.

Open lab-time

SQL Queries


Dailies

  • Submit today’s Codepen/repo/gist to the Dailies section (in Assessments) in Brightspace.