# Lab 1: Basic SQL Commands

In this lab you get experience using basic SQL commands, using SQLite.

## Setting up

Open a text document and this SQL interpreter (clear out the default SQL supplied). Throughout this exercise, test your SQL commands in the interpreter, but keep a copy of all of your working commands in your text document.

## Create tables

Use the `CREATE TABLE` command to match the structure given in the diagram above. Here is the first one to get you started:

    CREATE TABLE Customers(
    	CustomerID INTEGER PRIMARY KEY,
    	Name TEXT NOT NULL
    );

Remember to name the primary key similarly to the table (e.g. `CustomerID` in the `Customers` table). The other two tables each have a foreign key (e.g. the `Orders` table will have a `CustomerID` column). Feel free to use the lecture notes as a guide. In SQLite, the `Date` can be stored as a `VARCHAR(10)` of the form `YYYY-MM-DD`. For price we will use the INTEGER type and store the number of cents, because floating points are prone to roundoff error hence should not be used for currency (other DBMS's support specific currency types).

## Insert

Next, we will populate the tables using the INSERT command. For the customers table, use either `INSERT INTO Customers (Name) VALUES('DrKow');` or `INSERT INTO Customers VALUES(NULL, 'DrKow');` for the first customer. Fill in two more customers: 'Plato' and 'Socrates'. You can view your progress by using `SELECT * FROM Customers;` or another similar SELECT command.

Fill in the Orders and LineItems tables to reflect the following orders.

- On 2024-10-01, Plato ordered an NMU laptop for $165 and two power supplies for $22.95 each.
- On 2024-10-10, DrKow ordered an optical mouse for $12.99 and an HDMI to USB-C adapter for $10.99.
- On 2024-10-16, DrKow ordered an power supply for $22.95.

## Select

Now time for some `SELECT` commands. Write the following 5 queries:

- Show all data pertaining to all line items for Plato's order (you can use OrderID in the `WHERE` clause).
- Get the total for Plato's order by changing the `*` in your previous command to `SUM(Price)` instead. This is known as an aggregate function.
- Show the dates for all of DrKow's orders.
- Show the customer name and date for all orders (you will need a JOIN).
- Show the customer name and date for all orders, but still show the customers that never ordered anything (you will need a LEFT JOIN).

## Update

Using an UPDATE command, change the price of the USB-C adapter to $8.99 in the 2nd order.

## Delete

Using a DELETE command, delete the 2nd power supply from the first order.

When you are done, show me your work to get credit for it.