Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

COLLEGE OF ENGINEERING SCIENCE AND TECHNOLOGY

DEPARTMENT OF COMPUTING SCIENCE & INFORMATION SYSTEMS

SQL TUTORIAL AND RESEARCH QUESTIONS

Refer to the STOCK table given below to answer the following questions:

i. Write a SQL command to add the following set of data into the “stock table”

Code_Number Item_Name Type Quantity Unit_Price


112 Potatoes Food Item 15 Bags $1.55
113 Bleach Household 50 Gallons $3.25
Item

S2019001488 Nivikesh Ram


INSERT INTO stocktable (Code_Number, Item_Name, Type, Quantity, Unit_price)
VALUES (‘112’, ‘Potatoes’, ‘Food Item’, ’15 Bag’, ‘$1.55’);
INSERT INTO stocktable (Code_Number, Item_Name, Type, Quantity, Unit_price)
VALUES (‘113’, ‘Bleach’, ‘Household Item’, ’50 Gallons’, ‘$3.25’);

ii. Write a SQL command to change the Quantity of the stock, Code_Number 109 to 20
crates.

UPDATE stocktable
SET Quantity = ‘20 crates’,
WHERE Code_Number = 109;

iii. Write a SQL command to increase all Unit_price in the stock table by 20%.
UPDATE Unit_price
SET price = price + (price * 20.0 / 100.0)
WHERE Code_Number= ‘100’ and ‘101’and ‘102’ and ‘103’ and ‘104’ and ‘105’ and
‘106’ and ‘107’ and ‘108’ and ‘109’ and ‘110’ and ‘111’;

iv. Write a SQL command to delete all stocks with the type ‘Frozen Item’.

DELETE FROM stocktable WHERE Type='Frozen Item';

v. Write a SQL command to display the stock details for those stocks with Unit_Price
between $3.95 and $11.55.

CREATE VIEW [stock details] AS
SELECT Code_Number, Item_Name, Type, Quantity, Unit_price
FROM stocktable
WHERE Unit_price =‘>$3.95’ and ‘<$11.95’;

vi. Write a SQL command to list all stocks which are considered as Tin Stuff or Baby
Section

SELECT * FROM stocktable WHERE Type= ‘Tin Stuff’ and ‘Baby Section’;

vii. Write a SQL command to produce a list of Unit_Price for all stocks, arranged in
descending order of Unit_Price.

SELECT * FROM stocktable


ORDER BY Unit_price DESC;

S2019001488 Nivikesh Ram


viii. Write a SQL command to list all items whose Item_Name begins with C and
Unit_Price greater than $5.00 and state the resulting output in tabular form.

SELECT * FROM Item_Name WHERE CharIndex= ‘C’ and Unit_price= ‘>$5.00’;

S2019001488 Nivikesh Ram

You might also like