Академический Документы
Профессиональный Документы
Культура Документы
---------End-------
Q1. (a) What do you understand by primary key and candidate key. (2)
(c) Consider the table STUDENT given below, write SQL Commands for (i) to (iii) and output for
(iv) to (vi)
Q7. (A)Study the following table TEACHER and SALARY and write the SQL commands for the
questions (i) and (ii) and give outputs for SQL queries (iii) and (iv).
Table : TEACHER
Table : SALARY
SID BASIC ALLOWANCE DA
101 12000 1000 300
104 23000 2300 500
107 32000 4000 500
114 12000 5200 1000
109 42000 1700 200
105 18900 1690 300
130 21700 2600 300
i. Display NAME and DA of all staff who are in Accounts department and having more than 10 years of
experience and DA is more than 300. (2)
ii. Display the NAME and salary of all staff working in physics department and salary more than average
salary. (SALARY=BASIC +ALLOWANCE+ DA) (2)
iii. Select NAME, DA, BASIC from TEACHER, SALARY
Where BASIC>20000 and TEACHER.SID=SALARY.SID; (1)
iv. Select NAME, DEPT, SEX, BASIC, DA from TEACHER, SALARY
Where DEPT LIKE %o% and DA >=500 and TEACHER.SID=SALARY.SID; (1)
----------End-------
Q1. Write the commands in mysql based on empl and dept table.
a) Display details like deptno, dname, emplno, ename, job and salary. And order the rows by employee
number with department number.
b) Display the difference of higest and lowest salary of each department having maximum salary >
4000.
c) Display detail like deptno, dname,empno, ename,job and salary. And order the rows by employee
number with department number . these details should be only for employees earnin atleast Rs. 1500
and of SALES department.
d) Select * from empl e Join dept d on ( e.deptno= d.deptno). Write this query and see the output.
e) Select * from empl Natural Join dept. Write this query and display the output .
Q2 a) Table Employee has 4 records and table Dept has 3 records in it. Mr jain wants to display all the
information stored in both of these related tables. 1
SELECT * FROM EMPLOYEE ,DEPT ;
He forgot to specify equijoin. How many rows will get displayed on execution of this query?
b) There is a column c1 in table t1 . The following two statements are giving different outputs. What may
be the possible reason ? 1
SELECT COUNT(*)FROM T1;
SELECT COUNT(C1) FROM T1;
c) What are constraints ?Are they useful or not. Justify your answer. 2
d) Name two statements that can be used to end a transaction. 2
e) Write SQL statements for the queries (i) ,(ii) and output for (iii) and (iv): 4
Table: STORE
ItemNo Item Scode Qty Rate LastBuy
2005 Sharpener Classic 23 60 8 2009-06-31
2003 Ball Pen 0.25 22 50 25 2010-02-01
2002 Gel Pen Premium 21 150 12 2010-02-24
2006 Gel Pen Classic 21 250 20 2011-03-09
2001 Eraser Small 22 220 6 2009-01-19
2004 Eraser Big 22 110 8 2009-12-02
2009 Ball Pen 0.5 21 180 18 2009-11-03
Note: ItemNo is the Primary Key.
Q3 a)Identify Primary Key, Alternate Key, Candidate Keys in each table & Foreign Key from the following
two tables:
c) Display the sum of salary for each department with minimum salary as 20000 2
Q4. Select max(sal)- min(sal) difference from empl group by deptno having max(sal)>4000;
a). Select e.deptno, dname, emplno, ename, job and sal from empl e , dept d where e.deptno=d.deptno order
by e.deptno,empno;
b)Select e.deptno, dname, emplno, ename, job and sal from empl e , dept d where e.deptno=d.deptno and
dname=sales and sal>=1500 order by e.deptno,empno;
----------End-------