SQL COMMANDS
SQL COMMANDS
TABLE 1
Write SQL queries for (a) to (d) using the PRODUCT table details given below
PRODUCT
(a) Write the query to display details of all the product whose quantity must be greater
than 100.
SELECT * FROM PRODUCT WHERE QUANTITY>100;
(b) Write the query to increase the price of all the products by 5%;
UPDATE PRODUCT SET PRICE=PRICE+PRICE*5/100;
(c) Write the query to display details of the product where the Product name starts with
‘P’.
SELECT * FROM PRODUCT WHERE PNAME LIKE ‘P%’;
(d) Write the query to delete the record whose company name is ‘TOSHIBA’.
DELETE FROM PRODUCT WHERE COMPANY=’TOSHIBA’;
TABLE 2
2. Consider the following tables SENDER and RECIPIENT, Write SQL queries for
(a) to (d) using the SENDER and RECIPIENT table details given below .
SENDER
RECIPIENT
a) To display the names of all senders from Mumbai.
SELECT SENDERNAME FROM SENDER WHERE SENDERCITY=’MUMBAI’;
b) To display the recID, senderName, senderAddress, RecName, RecAddress
for every recipient.
SELECT RECID,SENDERNAME,SENDERADDRESS,RECNAME,
RECADDRESS FROM SENDER,RECIPIENT WHERE
SENDER.SENDERID=RECIPIENT.SENDERID;
c) List the sender name in alphabetical order.
SELECT SENDERNAME FROM SENDER ORDER BY SENDERNAME ASC;
d) To display reccity and the number of recipients from each city.
SELECT RECCITY,COUNT(RECID) FROM RECIPIENTS GROUB BY RECCITY;
TABLE 3
STATIONERY
a) Write the query to display product name, brand whose stock falls below 200
SELECT PNAME,BRAND FROM STATIONERY WHERE QTY <200;
b) Write the query to display the details of varieties of pens available in the
stationery STATIONERY
SELECT PNAME FROM STATIONERY WHERE PNAME LIKE ‘%PEN%;
c) Write the query to update the quantity of V7 pen to 175.
UPDATE STATIONERY SET QTY=’V7’ WHERE BRAND=’V7’;
d) Write the query to display the number of products purchased from each
brand.
TABLE 4
BOOK
ISSUED
a)To show Book name, Author name and Price of books of EPB publisher.
SELECT BOOKNAME,AUTHOR,PRICE FROM BOOK WHRE
PUBLISHER=’EPB’;
b) To increase the price of all books of First PubL.by 50.
UPDATE BOOK SET PRICE=PRICE+50 WHERE PUBLISHER=’FIRST PUBL’;
c) To display the Book_ID, Book_Name and Quantity Issued for all books which
have been issued.
SELECT BOOKID,BOOKNAME,QUANTITYISSUED FROM BOOK,ISSUED
WHERE BOOK.BOOKID=ISSUED.BOOKID;
d) To display the details of book which is of type ‘Fiction’.
SELECT * FROM BOOK WHERE TYPE=’FICTION’;
TABLE 5
GAMES
PLAYER
TABLE 6
WATCH
(b) Write the query to display the names of the watches which
is starting with alphabet ‘R’.
SELECT WNAME FROM WATCH WHERE WNAME LIKE ‘R%’;
TABLE 7
2. Consider the following tables EVENT and COMPANY. Write SQL queries for (a)
to (d) using the EVENT and COMPANY table details given below.
COMPANY
TABLE 8
PRODUCT
TABLE 9
SCHOOL
TABLE 10
EMPLOYEE
b) Write the query to update the salary of those employees by 2000 who have joined in
the year 2009.
UPDATE EMPLOYEE SET SALARY=SALARY+2000 WHERE JOINDATE BETWEEN
c) Write the query to add information about a new joinee with details like Tcode as 65,
Tname as ‘ADITHYA’, Depcde as 119 and age as 35 with a salary as 65000 joindate as
NULL
d) Write the query to display names of employees based on the order of their
experience from highest to lowest.