0% found this document useful (0 votes)
65 views

CST1340 - Week 3 - GOALs

SQL is used to communicate with databases and retrieve data. DDL is used to define the database structure and tables, while DML is used to manipulate the data by inserting, updating, and deleting records. The SELECT command is used to fetch data from a database table. To execute the SQL file containing the table creation code, a new schema needs to be created in MySQL Workbench, set as the default, and then the SQL file run to create the Product table for querying.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

CST1340 - Week 3 - GOALs

SQL is used to communicate with databases and retrieve data. DDL is used to define the database structure and tables, while DML is used to manipulate the data by inserting, updating, and deleting records. The SELECT command is used to fetch data from a database table. To execute the SQL file containing the table creation code, a new schema needs to be created in MySQL Workbench, set as the default, and then the SQL file run to create the Product table for querying.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Week 3 GOALs

Individual Task
Examine the following relation which are part of a database for a company
selling horse accessories. The products sold by the company are stored in
Warehouses.

Product
Product
No Description Price Warehouse No
(PK)
P001 Riding Hat £50 W010
P002 Jodhpurs £20 W020
P003 Back Support £60 W015
P004 Riding Boots £100 W010
P005 Jacket £150 W025

The code to create the above table is given in the Product.sql file. Download
the file and execute it.

You will be marked on the following GOALs:


These GOALs are all individual and worth 1 mark.

Answer the following:

I3.1. Explain what SQL is used for.

SQL is used for communication with databases.

I3.2. Discuss, using examples, the difference between DDL and DML.

DDL is data definition language. DML is data manipulation language. DDL eg:

CREATE, ALTER, TRUNCATE, RENAME, DROP. is used to specify the structure of

the database and DML eg: SELECT, UPDATE, DELETE, INSERT is used to insert,

update and delete records.

I3.3. Explain the syntax and purpose of the select command.

It is used to fetch the required data in a database.

I3.4. Connect to MySQL Workbench and set up a new connection.


I3.5. Explain how to execute a sql file to create the table given above.

Create a new schema, set is as default, create a table by running product.sql

Use the product table to answer the following:

I3.6. Write a SQL query to “List all product details”.

SELECT * FROM PRODUCT;

I3.7. Write a SQL query to “List the product number, description and price of each

product”.

SELECT product_No, description, price FROM Product;


I3.8. If the following SQL command was run, how would the resultant table differ

from the answer for I3.7 above:

Select product_No, price, description from Product;

It would be the same as the order does not matter.


I3.9. Write a SQL query to “List distinct product descriptions”.

SELECT DISTINCT description FROM Product;


I3.10. Explain the resultant table, if the following SQL command was run:

Select distinct description, price from Product;

If there are multiple products with the same description and price, only one of them will

appear in the result. This query focuses on distinct combinations of description and price,
so you may not get all products with unique descriptions; instead, you'll get unique

combinations of descriptions and prices.

For GOALs I3.6 to I3.10, the entry into your portfolio MUST contain the SQL code and a
screenshot of the resultant table after the code is run.

Note: Remember to build a section 1 portfolio to submit in week 4.

You might also like