
Adding and Modifying Data - Assignments
1. Create Table
We will start with a table for a shopping list.
Execute the query below.
This query creates:
- A table named
groceries. - The columns:
grocery_name: the name of an item.quantity: the required amount.
Do you understand why the respective data types were chosen?
Complete the following query to retrieve all data from the new table:
- Use
SELECTandFROM.
Is it logical what you see?
2. Add Rows
Complete the following query to add several rows to the groceries table.
'Tomatoes',5'Bananas',2'Apples',6
Use INSERT INTO and VALUES.
View the result with the query below:
3. Modify Values
A mistake was made. Therefore, an adjustment needs to be made.
Instead of 2, 3 bananas need to be bought.
With UPDATE, SET, and WHERE, we can make adjustments.
UPDATEallows you to make a change.- From
SET, you specify the intended change. - With
WHERE, you filter a selection that needs to be adjusted.
Complete the query below and make the adjustment:
View the result with the query below:
4. (Extra) Add Column
It is desired to keep more details of the groceries.
For this, a column needs to be added where the default store where you buy an item can be specified.
Complete the query below and make the adjustment.
- Add column
default_shop.- Data type
VARCHAR (50).
- Data type
View the result with the query below:
5. (Extra) Fill Column
The extra column is not yet filled with values.
Write a query to fill the new column default_shop with values:
'Tomatoes':'Lidl''Bananas':'Jumbo''Apples':'Albert Heijn'
Note: you can write multiple queries in succession.
View the result with the query below: