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

LAB MANUAL

S.No.. EXERCISES
1 Based on Joins:

Employee (id, first_name,last_name,start_date,end_date,salary,city)


Id First_name Last_name Start_date End_date Salary City
1 Jason Martin  1996-07- 2006- 1234.56  Toronto
25  07-25 
2 Alison Mathews 1976-03- 1986- 6661.78  Vancouver
21  02-21 
3 James  Smith  1978-12- 1990- 6544.78  Vancouver
12  03-15 
4 Celia Rice 1982-10- 1999- 2344.78  Vancouver
24  04-21 

Job select * from duty;
+------+-----------+
+------+------------+ | id   | task      |
| id   | title      | +------+-----------+
+------+------------+ |    1 | Test      |
|    1 | Tester     | |    2 | Calculate |
|    2 | Accountant | |    3 | Program   |
|    3 | Developer  | |    4 | Test      |
|    4 | Coder      | |    5 | Manage    |
|    5 | Director   | |    6 | Talk      |
|    6 | Mediator   | |    7 | Speak     |
|    7 | Proffessor | |    8 | Shout     |
|    8 | Programmer | |    9 | Walk      |
|    9 | Developer   +------+-----------+

Equi join:
1) Display employee first name, job and title and there should be no redundancy.
2) Display employee first name, job and title, task and there should be no redundancy.

Left join:
1) Retrieve first name, last name and title of the job having all the rows of employee
table.
2) Retrieve first name, last name and title of the job of coders even if the employee
corresponding to job title doesn’t exist, null should be displayed.
3) Retrieve first name, last name and task of coders even if the employee corresponding
to job title doesn’t exist, null should be displayed.
Right join:
1) Retrieve first name, last name and title of the job having all the rows of job table.
Self Join:
Create the table emp with attributes:  empno, ename, mgrno, hire_date
1)     Write a query to list out the names of the manager with the employee record one.
2)    Write a query to list all employees who joined the company before their manager.

select * from Authors;
+--------+--------+--------+--------+
| AuthID | AuthFN | AuthMN | AuthLN |
+--------+--------+--------+--------+
|   1006 | H      | S.     | T      |
|   1007 | J      | C      | O      |
|   1008 | B      | NULL   | E      |
|   1009 | R      | M      | R      |
|   1010 | J      | K      | T      |
|   1011 | J      | G.     | N      |
|   1012 | A      | NULL   | P      |
|   1013 | A      | NULL   | W      |
|   1014 | N      | NULL   | A      |
+--------+--------+--------+--------+

select * from Books;
+--------+----------------+-----------+
| BookID | BookTitle      | Copyright |
+--------+----------------+-----------+
|  12786 | Java           |      1934 |
|  13331 | MySQL          |      1919 |
|  14356 | PHP            |      1966 |
|  15729 | PERL           |      1932 |
|  16284 | Oracle         |      1996 |
|  17695 | Pl/SQL         |      1980 |
|  19264 | JavaScript     |      1992 |
|  19354 | www.java2s.com |      1993 |
+--------+----------------+-----------+

select * from AuthorBook;
+--------+--------+
| AuthID | BookID |
+--------+--------+
|   1009 |  12786 |
|   1006 |  14356 |
|   1008 |  15729 |
|   1011 |  15729 |
|   1014 |  16284 |
|   1010 |  17695 |
|   1012 |  19264 |
|   1012 |  19354 |
+--------+--------+
CROSS JOINS:-
1) Display author id corresponding to book title bt it shud be one to many relationship.
2) Display book’s title copyright,authors last name,fisrt name,middlename of the entries
having copyright after 1980 in ascending order.
3) Display first name ,last name and title of the job corresponding to every name.
2.
BASED ON VIEWS

(a) Write a query to create a view.


(b) Write a query to create a view with specified column names.
(c) Write a query to create a view with joined tables.
(d) Write a query by adding order by to the joined table view.
(e) Write a query to create a view by using group by clause.
(f) Write a query to drop a particular view.
(g) Write a query to alter a particular view e.g. to add a particular column.
(h) Create view on table employee with all the fields and display the view.
(i) Create view on table employee where city=”Vancouver” and display it.

(j) Create view vw_books on table Books renaming the column booktitle as title and
display it.

(k) Insert a new row in view vw_books with information(19356,”.net”,1994).

(l) Update the field title in view vw_books with value “sqlserver” where bookid=13331

(m) Delete the row from view vw_books where title=”php”.

(n) Create view on table employee with fields start date and salary and display it.

3 BASED ON INDEXES

(a) Write a query to create an index


(b) Write a query to create an index by using alter table statement
(c) Write a query to delete an index

4 BASED ON SUB-QUERIES

1.Create the table Client with attributes:  C_ID ,Name, City  and Create the table Product with
attributes:Prod_ID , Prod_Detail , C_ID , price   
a) Write a query to list of clients that are available in Products table.
b) Write a query to list of clients that are not available in Products table 

2.Create the table address with attributes:  First Name, Last Name, Street Address and Zip
Code of the members of your mailing list;
Create another table zipcode with attributes: City, State and Zip Code.

Write a query to find the names of the members of your mailing list who live in Georgia.

3.Find the name of the company that placed order 10290.


4.Find the Companies that placed orders in 1997.
5. Order data is stored in two tables. The orders table stores a single row for each order
containing order number, customer ID, and order date.
    The individual order items are stored in the related orderitems table. The orders table does
not store customer information. It only stores a customer ID.
    The actual customer information is stored in the customers table.

Find a list of all the customer ID who ordered item TNT2.


   

5 BASED ON STORED PROCEDURES AND FUNCTIONS

(a) WAP to create a procedure to calculate the area of a circle.


(b) WAP to create a function to calculate the circumference of a circle.
(c) WAP to create a function to calculate the weighted avg of 4 numbers.
(d) WAP to create a procedure to calculate the number of rows in employee
table.
(e) WAP to create a function to concatenate a string to show a welcome message.
(f) wap to create a procedure to calculate the minimum,maximum,and average
of a field employees salary.

(g) Wap for inserting the record and then selecting the record.
(h) Wap to find the category of the employee and then inserting it into a table.
(i) Wap to create a procedure using while loop.
(j) WAP to create a function by using IF-ELSE statement
(k) WAP to create a procedure by using CASE condition
(l) WAP to create a procedure by using REPEAT-UNTIL statement

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