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

Assignment 4

Uploaded by

janithadilsham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Assignment 4

Uploaded by

janithadilsham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CSC1213 Practical Assignment 04 2023

Database Management Systems (DBMS) - SQL using MySQL Server

Based on last week database (School_Items), practice the following the questions in your assignment.
Relevant data tables in the School_Items database as follows.

Item table

itCode itName price imported brand


IT10 Stapler 240.00 1 Mango
IT11 Pen 60.00 0 Atlas
IT12 Pencil 40.00 0 Atlas
IT13 Eraser 20.00 0 NULL
IT15 Backpack 4000.00 0 DSI
IT16 Notebook 160.00 NULL Atlas
IT17 Folder 20.00 1 Mango
IT18 Calculator 2700.00 1 Casio
IT19 Highlighter 150.00 0 NULL
IT20 Scissors 100.00 0 Mango
IT14 Flash Drive 1500.00 1 Kingston

bookShop table.

bsCode bsName contact address


BS01 Sarasavi 0112946058 Colombo 04
BS02 Godage NULL Main Street
BS03 Gunasena 0912546893 NULL
BS04 Samudra 0415670045 Dharmapala Mawatha

distribute table.

itCode bsCode qty date


IT10 BS01 30 2023-04-08
IT10 BS03 3 2023-04-02
IT10 BS04 10 2023-04-25
IT11 BS01 25 NULL
IT11 BS02 12 2023-05-07
IT13 BS04 60 2023-05-09
IT16 BS02 5 NULL

1. Find out the names of the databases created in your MySQL server.
show databases;

2. Activate the database you have created in las week. (ass3)


use school_items;

3. Find out the names of the tables you have created in your database.
show tables;

4. Retrieve all records from item table.


select * from item;
2023 - Department of Computer Science, University of Ruhuna, Matara, Sri Lanka. 1
5. Retrieve all records from bookShop table.

6. Retrieve all records from distribute table.

7. Examine structures of above three tables.


describe item;
describe bookShop;
describe distribute;

8. Sales details of the company are recorded in a table called sales. Create the structure for sales
table according to the details given below. (billNo should be define as the primary key)

Field name Description Field Property


billNo Bill number (Receipt number) Primary key
itCode Item code
bsCode Book Shop code
salesQty Sales quantity
salesDate Transaction date

9. Examine the structure of the table sales.

10. Insert following data into sales table.

billNo itCode bsCode salesQty salesDate


B1 IT10 BS01 3 2023-6-2
B2 IT10 BS03 1 2023-6-12
B3 IT13 BS04 15 2023-5-7
B4 IT11 BS01 12 2023-6-15
B5 IT11 BS02 5 2023-5-12

11. Retrieve itName and price from Item table

12. Retrieve the item codes from distribute table.

13. Retrieve the item codes without repetition from distribute table.

14. List the top 5 items in the item table

15. List the item names and prices for most cheapest 3 items

16. Find the cheapest item within the Atlas,Mango,DSI products.

17. Retrieve all records from Item table where price is greater than 1000.00.

18. Get the item names from the item table for known brands.

19. List the details of items from IT10 to IT19

20. List the item names end with er.

21. Select the details of items with a item code alphabetically between "IT10" and "IT19" from the
table item.

22. Select the details of items with a item code not between "IT10" and "IT19" from the table item.

2023 - Department of Computer Science, University of Ruhuna, Matara, Sri Lanka. 2


23. Get the item details which are available in either BS01 or BS04 book shops.

24. Retrieve names and prices of items which are available at the book shops which are identified by
the codes of BS01 or BS02 according to the descending order of the price.

25. Retrieve name, price and bsCode of items which are available at the book shops identified by
BS01 or BS02 according to the descending order of the bookshop code.

26. How many bookshops are available in the bookshop table?

27. How many steplers have been distributed by the company.

28. How many steplers have been distributed to the Gunasena book shop?

29. What is the largest unit price in the price column?

30. Find the item name which has the largest unit price.

31. List the names of items sold within the month, May 2023.

32. One customer is going to by 5 steplers with 10% discount. How many rupees have to be paid by
the customer for this deal?

33. Get the total price of the stepler stock, distributed to the BS01 bookshop.

34. Get the total price of the stepler stock, distributed to the Sarasavi bookshop.

2023 - Department of Computer Science, University of Ruhuna, Matara, Sri Lanka. 3

You might also like