SQL
SQL
1 Observe the following tables Customers and Orders and write queries given below:
Table – Customer
Table – Order
Ans.: select orderid, orderdate, customername, mobileno from customer, order where
customer.customerid = order.customerid and (customername like ‘%k’ or customername like
‘%h%’;
i. Write command to add primary key and foreign key in tables using alter.
ii. Increase the price of all computer books by 70.
iii. Display the book id, book name and quantity issued for all books which have been
issued.
iv. Display the book id, book name, author name, quantity issued for allbooks which
price are 200 to 400.
Ans.:
alter table books add primary key (BID);
alter table issued add foreign key references books (bid);
Ans.:
update books set price=price + 70 where type='computer';
Ans.:
select books.bid,bname,qty_issued from books,issued where books.bid=issued.bid;
Ans.:
select books.bid,bname,auname,qty_issued from books,issued
where books.bid=issued.bid and price>=200 and price<=400;
Q.3 Write queries (a) to (d) based on the tables EMPLOYEE and DEPARTMENT given
below:
i. .
ii
iii
iv