2.12: Solutions

2.3 Create Table Solution

To create a table for Products with the specifications outlined in the challenge, enter the following code in a SQL query:

CREATE TABLE Products (
    ProductID int PRIMARY KEY NOT NULL,
    ProductName varchar(25) NOT NULL,
    Price money NULL, -- you can add notes to your queries
    ProductDescription text NULL
);

This is what the resulting view will look like in pgAdmin after you've run the query:

Query View in pgAdmin

2.4 Insert Solution

2.5 Update Solution

2.6 Read Solution

2.7 Alter Solution

Add a column called "Manufacturer":

Drop the "Manufacturer" column:

Add a column called "UPC" with data type VARCHAR(25):

Change the "UPC" column to a TEXT data type:

Drop the "UPC" column:

2.8 Customer Table Solution

Create a "Customers" table with the specified criteria:

Seed table with specified data:

This is what your resulting table should look like:

Table with seed data in pgAdmin

2.9 Diagramming Notation Solution

Diagramming Notation Solution Table

2.10 Foreign Keys Solution

Purchase Table Solution

Copy and paste the code below into a new query. You'll need it for the next lesson.

2.11 Join Solution

This is what your query should look like:

Last updated