Вы находитесь на странице: 1из 2

SQL

Q1. What are views?


Q2. What is difference between drop table and drop view?
Q3. What is the difference between count and count(*)?
Q4. What do you understand by constraints?
Q5. Consider the following table and answer question given below:
TNo. Name Age Department Dateofjoin Salary sex
1 Jugal 34 Computer 10/10/98 12000 M
2 Sharmila 32 History 10/1/97 15000 F
3 Sandeep 35 Hindi 12/3/98 12000 M
4 Sangeeta 28 Hindi 12/8/99 11000 F
5 Rakesh 29 History 10/5/97 13000 M
6 Shyam 31 Maths 12/5/99 11000 M
7 Shiv om 35 Maths 10/5/98 12000 M
8 Bindiya 26 Computers 12/5/97 15000 F
(i) To show all the female history teachers
(ii) To show name and salary of teachers joined after 1/1/98 in ascending order of name
(iii) To show name, monthly and yearly salary of teachers
(iv) To display all teachers whose name start with s in descending order of salary
(v) To display total salary in each department
(vi) Insert a record
(vii) Count no of female teachers of school.
(viii) What will be the output
(i) select max(salary) from teacher
(ii) select avg(salary) form teacher where department=”Computer”
(iii) select * from teacher where name = “Bindiya”
(iv) Select count(distinct age) from teacher
Consider a table child
Tno Name Age class
1 Riti 7 2
7 Priti 8 3
8 Sonu 7 2

(ix) Show teacher name and child name


(x) Count no teacher whose child are in school
(b) Consider the following WORKERS and DESIG. Write SQL commands for the statements (i) to
(iv) and give outputs for SQL queries (v) to (viii)
WORKERS
W_ID FIRSTNAME LASTNAME ADDRESS CITY
102 Sam Tones 33 Elm St. Paris
105 Sarah Ackerman 440 U.S. 110 New York
144 Manila Sengupta 24 Friends Street New Delhi
210 George Smith 83 First Street Howard
255 Mary Jones 842 Vine Ave. Losantiville
300 Robert Samuel 9 Fifth Cross Wasington
335 Henry Williams 12Moore Street Boston
403 Ronny Lee 121 Harrison St. New York
451 Pat Thompson 11 Red Road Paris

DESIG
W_ID SALARY BENEFITS DESIGNATION
102 75000 15000 Manager
105 85000 25000 Director
144 70000 15000 Manager
210 75000 12500 Manager
255 50000 12000 Clerk
300 45000 10000 Clerk
335 40000 10000 Clerk
400 32000 7500 Salesman
451 28000 7500 Salesman
(i) To display W_ID, FIRSTNAME, ADDRESS and CITY of all employees living in
NEW YORK from the table WORKERS.
(ii) To display the content of workers table in ascending order of LASTNAME.
(iii) To display the FIRSTNAME, LASTNAME and total salary of all perks from the tables
WORKERS and DESIGN, where total salary is calculated as SALARY + BENEFITS.
(iv) To display the minimum salary among Managers and Clerks from the table DESIG.
(v) Add a record in worker table
452, “Patrick”,”Thomas”,”12 Hudson Lane”,”Paris”
(vi) Delete record of worker whose id is 403
(vii) Update salary of managers by 1000
(viii) SELECT FIRSTNAME, SALARY FROM WORKERS, DESIG WHERE
DESIGNATION = ‘Manager’ AND WORKERS.W_ID = DESIG.W_ID
(ix) SELECT COUNT(DISTINCT DESIGNATION) FROM DESIG.
(x) SELECT DESIGNATION, SUM(SALARY FROM DESIGNATION GROUP BY
DESIGNATION HAVING COUNT(*)<3;
(xi) SELECT SUM(BENEFITS) FROM WORKERS WHERE DESIGNATION = ‘Salesman’;

Вам также может понравиться