0% found this document useful (0 votes)
80 views

Test 4 SQL

Uploaded by

jerujef.2723
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

Test 4 SQL

Uploaded by

jerujef.2723
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

SQL

1. Consider the following tables Stationary and Consumer. Write SQL commands for the
statement (i) to (iv).

To display the details of those consumers whose Address is Delhi.


(i) To display the details of Stationary whose Price is in the range of 8 to 15. (Both Value
included)
(ii) To display the ConsumerName, Address from Table Consumer, and Company and
Price from table Stationary, with their corresponding matching S_ID.
(iii) To increase the Price of all stationary by 2
2. Consider the following tables FACULTY and COURSES. Write SQL commands for
the statements (i) to (iv)

i) To display details of those Faculties whose salary is greater than 12000.


ii) To display the details of courses whose fees is in the range of 15000 to 50000 (both
values included).
iii) To increase the fees of all courses by 500 of “System Design” Course.
iv) To display details of those courses which are taught by ‘Sulekha’ in
descending order of courses.
3. Categorize the DDL and DML commands.
i) Update ii) Delete iii) Alter iv)Select v)Drop vi) Create vii) Insert
4. Differentiate Candidate, Primary, Alternate and Foreign keys with suitable
example.
5. Write SQL queries for (i) to (iv)
(i)To display details of all Trains which Start from New Delhi.
(ii) To display the PNR, PNAME, GENDER and AGE of all Passengers whose AGE is
below 50.
(iii) To display total number of MALE and FEMALE Passengers.
(iv)To display details of all Passengers travelling in Trains whose TNO is 12015.
6. Write SQL queries for (i) to (iv)

(i) Display the Trainer Name, City & Salary in descending order of their Hiredate.
(ii) To display the TNAME and CITY of Trainer who joined the Institute in the month of
December 2001.
(iii) To display TNAME, HIREDATE, CNAME, STARTDATE from tables TRAINER
and COURSE of all those courses whose FEES is less than or equal to 10000.
(iv) To display number of Trainers from each city.
(v) What is the degree and cardinality of the COURSE table?
7. Define referential integrity constraint.
8. Define attribute, domain and relation.
9. Write the queries for the i) to iv) based on the given tables.
i) To show firstname, lastname, address and city of all employees living in paris
ii) To display the content of Employees table in descending order of Firstname.
iii) To display the firstname, lastname and totalsalary of all managers from the tables
Employee and empsalary, where totalsalary is calculated as salary+benefits.
iv) To display the maximum salary among managers and clerks from the table
Empsalary.
v) What will be the degree and cardinality of the resultant table when Cartesian product
is performed on the tables-EmpSalary and Employees.
10. Consider the table CD and TYPE given below and answer the questions.
Table : CD
Table : Type

a) Name the Primary key in ‘‘CD’’ table.


b) Name the foreign key in ‘‘CD’’ table.
c) Write the Cardinality and Degree of ‘‘TYPE’’ table.
d) Check every value in CATEGORY column of both the tables. Do you find any
discrepancy? State the discrepancy.
11. Write the outputs of the SQL queries (i) to (iv) based on the relations Teacher and
Placement given below:
Table : Teacher
Table : Places

(i) SELECT Department, sum(Salary) FROM Teacher WHERE Salary>12000


GROUP BY Department;
(ii) SELECT MAX(Date_of_Join),MIN(Date_of_Join) FROM Teacher WHERE
Gender=’M’;
(iii) SELECT Name, Salary, T.Department, Place FROM Teacher T, Placement P
WHERE T.Department = P.Department AND T.Department Like ‘%o%;
(iv) SELECT Name, Place FROM Teacher T, Placement P WHERE Gender =’M’
AND T.Department=P.Department;
12. Consider the tables itemmast and itemtran and construct SQL query for the following,
TABLE: ITEMMAST

TABLE: ITEMTRAN

a. To display total_sales by item_no from itemtran table


b. Add column remarks of varchar type after item_qty in itemmast table
c. Add a remark entry 'Price hike likely' in itemmast for the item laptop.
13. Consider the following tables and write the output for the given queries i) to vi)
TABLE: CAR
Ccode Cname Make Colou Capacity Charges
r
201 Triber Renault NULL 7 1000
203 Altroz Tata Black 5 1500
208 Innova Toyota Silver 8 3000
209 Harrier Tata NULL 6 2000
212 Duster Renault Red 6 2500
217 Ertiga Suzuki Grey 7 2300
TABLE : CUSTOMER

i) SELECT CNAME, MAKE AS MANUFACTURER, CAPACITY FROM CAR;


ii) SELECT * FROM CAR WHERE CNAME LIKE “%r”;
iii) SELECT CAR.CCODE, MAKE, CHARGE, CUSTNAME FROM
CAR,CUSTOMER WHERE CAR.CCODE = CUSTOMER.CCODE;
iv) SELECT * FROM CAR WHERE CHARGE BETWEEN 2000 AND 2500;
v) SELECT CUSTCODE, CUSTNAME, CHARGES*12 AS
ANNUAL_AMOUNT FROM CAR, CUSTOMER WHERE CAR.CCODE =
CUSTOMER.CCODE;
vi) SELECT CNAME, MAKE FROM CAR WHERE COLOUR IS NULL;
14. Differentiate where clause and having clause.
15. What is the significance of having a primary key constraint?

You might also like