You are on page 1of 2

1.

Create a database named: products


create database products;

2. View all databases


show databases;

3. Select the "products" database as your new active database


use products;

4. Create a table named: fruits (as illustrated above) f_id integer, primary key, auto-increment
f_name varchar f_price decimal f_quantity int
CREATE TABLE fruits (f_id int auto_increment, f_name varchar(50), f_price decimal(10,2),
f_quantity int(10),primary key(f_id));

5. Verify that the table "fruits" exists by showing all the tables in the "products" database
show tables;

6. Insert 5 the entries (as shown above) in fruits table (show only your first solution)
INSERT INTO fruits (f_name,f_price,f_quantity) VALUES ("APPLE","25.50","25");

INSERT INTO fruits (f_name,f_price,f_quantity) VALUES ("BANANA","35.00","5");

INSERT INTO fruits (f_name,f_price,f_quantity) VALUES ("CHERRY","120.75","45");

INSERT INTO fruits (f_name,f_price,f_quantity) VALUES ("GRAPES","82.35","15");

7. View all the data stored in fruits table


SELECT * FROM fruits;

8. Delete the record that contains "Durian" using f_id as your key
DELETE FROM fruits WHERE f_id='4';

9. Add another record with the following data: f_name Orange f_price 26.35 f_quantity 12
INSERT INTO fruits (f_name,f_price,f_quantity) VALUES ("ORANGE","26.35","12");

10. View all the data stored in "fruits" table and make sure that it looks like the following:
SELECT * FROM fruits;

11. Modify the table and include the following attribute: f_unit varchar(20)
ALTER TABLE fruits ADD COLUMN f_unit VARCHAR(20);

12. Modify the table and include the following attribute: f_reorder int(4)
ALTER TABLE fruits ADD COLUMN f_reorder int(4);

13. Update your table using only a single SQL command so that all f_reorder columns would
have a value of '100'
UPDATE fruits SET f_reorder='100';

14. Update your table using one SQL command only so that the following fruits (Apple and
Orange) will have a f_unit value of "Piece" (Use f_name as your key)
UPDATE fruits SET f_unit='Piece' WHERE f_name IN
('APPLE','ORANGE');

14. Update your table and make the f_unit of Banana to "Bunch" (Use f_id as your key)
UPDATE fruits SET f_unit='Bunch' WHERE f_id='2';

15. Update your table using only one SQL command and make the f_unit of of all fruits whose
price is greater than 50.00 to "Kilo"
UPDATE fruits SET f_unit='Kilo' WHERE f_price>50.00;

17. Show all the data in fruits table. The result must be sorted by price in descending order.
SELECT * FROM fruits ORDER BY f_price DESC;

18. Delete the table fruits.


DROP TABLE fruits;

19. Delete the database products.


DROP DATABASE products;

20. Properly exit the MySQL Command Prompt


exit;

You might also like