extra qa dbms with solutions
extra qa dbms with solutions
(ii) SELECT TNAME, CITY FROM TRAINER WHERE HIREDATE BETWEEN ‘2001-12-01’ AND ‘2001-12-31’;
(iii) SELECT TNAME, HIREDATE, CNAME, STARTDATE FROM TRAINER, COURSE WHERE TRAINER.TID=COURSE.TID AND
FEES<=10000;
(v) SELECT TID, TNAME, FROM TRAINER WHERE CITY NOT IN(‘DELHI’, ‘MUMBAI’);
i) To display details of all the items in the Store table in descending order of LastBuy.
ii) To display Itemno and item name of those items from store table whose rate is more than 15 rupees.
iii) To display the details of those items whose supplier code is 22 or Quantity in store is more than 110 from the table
Store.
iv) To display minimum rate of items for each Supplier individually as per Scode from the table Store.
v) To display ItemNo, Item Name and Sname from the tables with their corresponding matching Scode.
(ii) Select Itemno, Item from store where rate > 15;
(v) Select Itemno, Item, Store.scode, Sname from Store, Suppliers where Store.scode = Suppliers.scode;
OUTPUT:- (i) 43000
08-10-1995 05-071993
F 3
M 3
a) Create table WORKER(WORKER_ID varchar(3), FIRST_NAME varchar(10), LAST_NAME varchar(10), SALARY
integer, JOINING_DATE Date, DEPARTMENT varchar(10));
b) WORKER_ID
Observe the following table and answer the question (a) to (e)
(a) Write the name of most appropriate columns which can be considered as Candidate keys?
(b) Out of selected candidate keys, which one will be the best to choose as Primary Key?
(c) What is the degree and cardinality of the table?
(d) Insert the following data into the attributes VisitorID, VisitorName and ContactNumber respectively in the given
table VISITOR.
VisitorID = “V004”, VisitorName= “VISHESH” and ContactNumber= 9907607474
(e) Remove the table VISITOR from the database HOTEL.
Answer:
(a) VisitorID and ContactNumber
(b) VisitorID
(c) Degree= 3 Cardinality=4
(d) insert into VISITOR values (“V004”, “VISHESH”,9907607474)
(e) DROP TABLE VISITOR;
i) To decrease period by 10% of the teachers of English subject.
ii) To display TEACHERNAME, CODE and DESIGNATION from tables SCHOOL and ADMIN whose gender is male.
iv) To display details of all teachers who have joined the school after 01/01/1999 in descending order of
experience.
v) Delete all the entries of those teachers whose experience is less than 10 years in SCHOOL table.
Answer:
iv) select * from SCHOOL where DOJ>’ 01/01/1999’ order by EXPERIENCE desc;
(ii) List the details of mobile whose name starts with “S” or ends with “a”.
(iii) Display the Mobile supplier & quantity of all mobiles except “MB003”.
(iv) List showing the name of mobile company having price between 3000 & 5000.
Answer:
(ii) SELECT * FROM MobileMaster WHERE M_Name LIKE “S%” or M_Name LIKE “%a”;
(iv) SELECT M_Company FROM MobileMaster WHERE M_Price BETWEEN 3000 AND 5000;
Price - Decimal
d) Give the command to remove all the records from the table.
e) Write a query to create the above table with Drinkcode as the Primary Key.
b) Cardinality = 6, Degree = 4
Write the outputs of the SQL queries i) to iii) based on the tables given below:
ii) Select CName, Manufacturer from Item, Customer where Item.ID = Customer.ID;
iii) Select Item_Name, Price * 100 from Item where Manufacturer = “ABC”;
A CD/DVD Shop named “NEW DIGITAL SHOP” stores various CDs & DVDs of songs/albums/movies and use SQL
to maintain its records. As a Database Administrator, you have decided the following:
Name of Database - CDSHOP
Name of Relation - LIBRARY
Attributes are:-
(a) CDNO - Numeric values
(b) NAME - Character values of size (25)
(c) QTY - Numeric values
(d) PRICE - Decimal values
4&6
(b) Identify the best attribute which may be declared as Primary key. 1
CDNO
(c) Insert the following record in the above relation: (10009, ”Motivational Songs”, 15, 70)
(e) Database administrator wants to count the no. of CDs which does not have any Price value. Write the query for
the same.
Consider the table TEACHER given below. Write commands in SQL for (i) to (iii)
ii. To list names, departments and date of hiring of all the teachers in descending order of date of joining.
iii. To count the number of teachers and sum of their salary department wise.
Ans i) SELECT * FROM TEACHER WHERE CATEGORY= ‘PGT’ AND GENDER= ‘F’;
ii) SELECT NAME, DEPARTMENT, HIREDATE FROM TEACHER ORDER BY HIREDATE DESC;
a. To display the RecIC, Sendername, SenderAddress, RecName, RecAddress for every Recipient
a. Select R.RecIC, S.Sendername, S.SenderAddress, R.RecName, R.RecAddress from Sender S, Recepient R where
S.SenderID=R.SenderID ;
Write SQL commands for (i) to (v) on the basis of relations given below:
(i) To show the books of FIRST PUBL. Publishers written by P. Purohit.
(iv) To display the BOOK_NAME and price of the books, more than 5 copies of which have been issued.
i) SELECT * FROM BOOKS WHERE PUBLISHER LIKE „FIRST PUBL.‟ AND AUTHOR_NAME LIKE „P. Purohit‟;
iii) UPDATE BOOKS SET PRICE = PRICE * 0.90 WHERE PUBLISHER LIKE “EPB‟;
iv) SELECT BOOK_NAME, PRICE FROM BOOKS B, ISSUED I WHERE B.BOOK_ID = I.BOOK_ID AND QTY_ISSUED > 5;