Sunteți pe pagina 1din 8

HR A ENT UE F E HOOY E I G I S I T O TC N L G T T

2011, ODD SEMESTER

Paper: DBMS LAB


1. Create the following tables: Table Name: DEPT Column Name Dno Dname Table Name: EMPL Column Name Eno Ename City Salary Dno Join_date Data Type Number Varcher2
Data Type

Computer Science and Engineering Assignment No 1

Paper Code: CS592

Size 2 15 Size 2 10 10
,

Constraints Primary key

Char Varchar2 Varchar2 Number Number Date Size 2 2

Constraints Primary key and first character must be "E" Not Null Cities allowed Chennai, Mumbai, Delhi , Kolkata Foreign key reference DEPT table

6 2

Table Name: PROJECT Column Name Data Type Pno Char Eno Char

Constraints Primary key and first character must be P Primary key and Foreign key reference EMP table

2. Insert the following data into the corresponding table: Table: DEPT Dno Dname 1 Research Name: Roll: 1

CS592 2 Finance Table: EMPL Eno El E2 E3 E4 E5 Ename Ashim Kamal Tamal Asha Timir City Kolkata Mumbai Chennai Kolkata Delhi Eno EI E3 E5 EI Dno 1 2 1 2 1 Join_date 01:Jun-02 02-Jan-02 07-Feb-04 01-Mar-07 11-Jun-05

Salary

10000 18000 7000 8000 7000

Table: PROJECT Pno PI P2 PI P2 3. Write the SQL queries:

1. a) Display all employees having "a" as the second letter in their names. b) Display employee names for those who joined in the month of Jun. c) Display names of all employees in the alphabetic order. d) Find the average salary of all employees. 2. a) Display employees names and department names of all employees who belong to either Chennai, or Kolkata or Mumbai. b) List all the employee names whose basic is greater than 7000 and less than 15000. c) Display list of all employees in department no. 2. . d) Display the no. of employees in each department.
,

3. a) List the names of all employees who get the same basic pay as that of employee "Tamal". b) Display the joining date of all employees in dd/mm/yy format. c) Find all departments that have more than 3 employees. d) Find the difference between highest and lowest salary.

Name:

Roll No:

CS592 4. a) Display the names of all employees who are engaged in two or more projects. b) List of all employees who have salary between 2000 &10000. c) List details of all employees in department number 2 & 1.

5. a) Display employee number, employee name and basic pay for employees with lowest salary.
b) Display the structure of table EMP. c) List the name and the salary of all employee sorted by salary. d) Display the list of all employees who were hired during 2002. 6. a) Display employee name and basic pay for all employees who are engaged with at least one project. b) List of all employees who have name exactly 4 characters. c) List no. of projects undertaken in the department 1.

Assignment No 2
1. Create the following tables and enter some data: Table Name: EMPLOYEE Column Name Data Type Emp_no Char Emp_name Varchar2 Street Varchar2 Varchar2 City Table Name: COMPANY Column Name Data Type comp_no Char comp_name Varchar2 City Varchar2

Size 2 10 10 10

Constraints Primary key and first character must be "E" Not Null Cities allowed Chennai, Mumbai, Delhi, Kolkata

Size 2 10 10

Constraints Primary key and first character must be "C" Not Null Cities allowed Chennai, Mumbai, Delhi, Kolkata Roll No: 3

Name:

CS592 Table Name: WORKS Column Name Data Type Emp_no Char Comp_no Char Salary Number Table Name: MANAGER Column Name Data Type Emp_no Char manager_name Varchar2 Size Constraints 2 Primary key and Foreign key references employee table 2 Primary key and Foreign key reference company table 6

Size Constraints 2 Primary key and first character must be "E" 10 Not Null

2. Insert the following data into the corresponding table: Table: EMP Emp_no Emp_name El Ashim E2 Kamal E3 Tarnal E4 Asha E5 Arun Table:WORKS Emp_no Comp_no E1 C1 E2 C3 E3 C2 E4 C1 E5 C3

City Kolkata Mumbai Chennai Kolkata Mumbai

Street Park Street Marine Drive Anna Salai Lenin Sarani M. G. Road

Salary 10000 20000 22000 18000 17000

Name:

Roll No:

CS592 Table:COMPANY Comp_no Comp_name C1 IBM C2 CTS C3 TCS City Kolkata Chennai Mumbai

Table:MANAGER Emp_no Manager_name El Ashim E2 Kamal E3 Tarnal 2. Write an expression in SQL for each of the following queries: 1. Find the names of all employees who work for SBI. 2. Find the names and cities or residence of all employees who work for SBI. 3. Find the names, street, address and cities of residence of all employees who work for SBI and earn more than 10,000. 4. Find all employees in the database who live in the same cities as the companies for which they work. 5. Find all employees in the database who live in the same cities and on the same streets as do their managers. 6. Find all employees in the database who do not work for SBI. 7. Find all employees in the database who earn more than every employee of SBI. 8. Find all employees who earn more than the average salary of all employees of their company. 9. Find the company that has the most employees. 10. Find the company that has the smallest payroll. Name: Roll No: 5

CS592 11. Find those companies whose employees earn a higher salary, on average, than the average salary at SBI. 12. Modify the database so that John now lives in Kolkata. 13. Give all employees of SBI a 10 % raise. 14. Give all managers of SBI a 10 % raise. 15. Delete all rows in works relation for employees of SBI.
.

Assignment No 3
1. Create the following tables: Table: Department Column Name Dno Dname Table: Employee Column Name Eno Ename Salary JoinDate Birthdate Dno Address ManagerId Data Type With Size Number (4) Varchar2 (10) Constraint With Size Primary key Not null

Data Type With Size Varchar2(5) Varchar2(10) Number(7,2) Date Date Number(4) Varchar2(20) Varchar2(5)

Constraint With Size Primary key and 1st character is 'E' Not null Within 5000 to 30000, both inclusive
.

Foreign key references department Data must be available in Eno field

Name:

Roll No:

CS592 2. Write down the following queries: a) Find the number of employees in each department with department name. b) Find the employees who earn highest salary in each department. c) Find the name of the employees who has the second highest salary. d) Find the name and salary of employee with the name and salary of their manager. e) Find the name of employees whose Joining month and birth month are same.

Assignment No 4
1. Create a table account and insert the following data into the table: Table: Account Account No AI A2 A3 A4 AS a) b) Branch Name Kolkata Howrah Howrah Kolkata Durgapur Amount (Rs.) 50000 40000 40000 20000 30000

Create a view that will show the branch name and total amount of that branch. The name of the view will be Account1. Select the branch names having total amount greater than 50,000 I) using Accountl view II) without using the view.

Assignment No 5
1. Write a PL/SQL to print the string "HELLO WORLD". 2. Write a PL/SQL to test whether a number is even or odd. Name: Roll No: 7

CS592 3. Write a PL/SQL code to check whether a number is prime or not. 4. Write a PL/SQL to insert a record in the accounts table of assignment 4.

Assignment No 6
1. Write a PL/SQL program to calculate factorial of a given number. 2. Write a PL/SQL program to print first N Fibonacci number. 3. Write a PL/SQL block of code for inverting a number 5639 to 9365. 4. Write a PL/SQL block to calculate maximum of three numbers.

Assignment No 7
1. a) Write a PL/SQL code block to display the area of a circle of a value of radius varying from 3 to 10 in steps of 1. Get the radius data from the CircleIn (radius) table (Create the table if necessary). b) Add an extra column diameter to the table Circle and update the diameter column for each entry diameter = 2 * radius. c) Print the number of records in the circ1e table with the help of an explicit cursor.

2. A HRD manager has decided to raise the salary for all the employees in department number 20 by 0.05. Whenever any such raise is given to employees, an audit trail of the same is maintained in the emp_raise table. The emp_raise table holds the employee number, the date when the raise was given and the raise amount. Write a PL/SQL block to update the salary of each employee of dept_no 20 appropriately and insert a record in the emp_raise table as well. Tables are as following:- Staff(emp_code, ename, deptno, job, salarly), Emp_raise (emp_code, aise_date, raise_amt). Add necessary data in the table. Name: Roll No: 8

S-ar putea să vă placă și