Sie sind auf Seite 1von 8

VIT

UNIVERSITY
(Estd. u/s 3 of UGC Act 1956)

SCHOOL OF INFORMATION TECHNOLOGY AND


ENGINEERING
Subject : DBMS Lab
Course : V SEM B.TECH- IT.

Cycle Sheet – I

1. a) Create a table EMP with the following fields.

Column name Datatype Constraint Type

EName Varchar2(20) NOT NULL


Eno. Number(5) PRIMARY KEY
Salary Number(5,2) CHECK salary >1000
DeptNo Number(4) FOREIGN KEY
Address Varchar2(15) NOT NULL
Dname Varchar2(10) NOT NULL

a) Insert 5 records into EMP


b) Display the name and salary of employee earning more than 5,000.
c) Display the name and salary for all employee whose salary is not in the
range of 5,000 and 12000
d) Drop primary key constraint for Eno.
e) Add primary key constraint for Eno.
g) Update the salary of the Employees by 10% hike
h) Delete the employees whose name is ‘AAA’

2. Create a table ORDER with the following fields and constraints.


ORDER
Column Name Constraint Name Constraint Type
Order-no pk-order-no PRIMARY KEY
Item-name itn UNIQUE
Qty ck-aty CHECK (25<QTY<50)
rate-unit Nn-rate NOT NULL

a) Drop unique constraint for Item-name


b) Remove the PRIMARY KEY constraint for Order-no
c) Add the PRIMARY KEY constraint for Order-no.
d) Disable the constraint Nn-rate
e) Insert a record with NULL value for rate unit
f) Enable the constraint Nn-rate
g) Insert a record with NULL values for rate unit
h) Enable the constraint with NULL value existing on rate-unit

3. Create a table called SUPPLIER, with columns as given below. In


addition, define
SUPP_ID as primary key.
Column Name Data type Constraint Type

SUPP_ID NUMBER(4) PRIMARY KEY


SUPP_NAME VARCHAR2(15) NOT NULL
CITY VARCHAR2(15)
STATE VARCHAR2(15)

Create a table called PURCHASE_ORD with columns as given below. In


addition define
PO_ID as primary key column, ensure that ORD_DT is less than SHIP_DT.
Column Name Data type Constraint Type
PO_ID NUMBER(4) PRIMARY KEY
ORD_DT Date
SHIP_DT Date
SUPP_ID NUMBER(4) FOREIGN KEY
ORD_QTY NUMBER(10) NOT NULL
a) Delete the rows from SUPPLIER table that does not matching rows in
the
PURCHASE_ORD table.
b) Add UNIQUE constraint for CITY.
c) Add NOT NULL constraint for STATE.
d) Drop the UNIQUE constraint and add NOT NULL constraint for
CITY.
e) Add NOT NULL constraint for SHIP_DT and ORD_DT
f) Disable NOT NULL constraint for SHIP_DT
g) Insert a record with NULL values for SHIP_DT
Cycle Sheet – II

Create a table EMPLOYEE with the following fields.

EMPLOYEE

Column name Constraint Type Datatype


EMP_ID NOT NULL NUMBER (6)
FIRST_NAME VARCHAR2 (20)
LAST_NAME NOT NULL VARCHAR2 (25)
EMAIL NOT NULL VARCHAR2 (25)
PHONENUMBER NOT NULL VARCHAR2 (15)
HIREDATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2 (25)
SALARY NUMBER (8, 2)
COMMISION NUMBER (4, 2)
MANAGER_ID NUMBER (6)
DEPARTMENT_ID NUMBER (4)

1. Calculate the annual compensation as 12 multiplied by the monthly salary,


plus a one time bonus of $100 Note that multiplication is performed before
addition.
2. Display the last names and hire dates of all employees who joined
between January 1995 and December 1995.
3. Displays the lastname and job id of all employees whose job id is not
IT_PROG , ST_CLERK or SA_REP.
4. Select the row if an employee is a president and earns more than $15,000
or if the employee is a sales representative.
5. Display the employee id, last name and the date by annual salary.
6. Display the lastname, salary and commission of all employees order the
result by department and then in descending order by salary and
commission.
7. Display the employee lastname, jobid and start date of employees hired
between February 20, 1998 and May 1, 1998 order the query in ascending
order by start date.
8. Display the last name and hiredate of every employee who was hired in
1994.
9. Display the First name and job title of all employees who don’t have a
manager.
10. Display the lastname and department no of all employees in departments
20 and 50 in alphabetical order by name.
11. Display the last names of all employees where the 3rd letter of the name
is ‘a’.
12. Display the last name of all employees who have ‘a’ as first letter and ‘e’
as last letter in their lastname.
13. Calculate the remainder of salary after it is divided by 5000 for all
employees whose job title is ‘sales’.
14. Display the last name concatenated with the job id, separated by a
comma and space and name the column employee and title.
15. Display empid, last name, jobid of all employees whose jobid has an
‘SA_’.
16. Display the last name, job and salary for all employees whose job is
sales representative or stock clerk and whose salary is not equal to $2500,
$3,400 or $7000.
17. Write a query to display the current date label the column name as
‘Date’.
18. Write a query for each employee display the employee no, last name and
salary increased 15% and expressed as a whole number.
19. Write a query that displays the employees last names with the first letter
capitalized and all other letters case and the length of the names, for all
employees whose name starts with J,A or M.
20. Retrieve the name of departments in ascending order and their
employees in descending order.
21. Compute Anu’s Yearly salary.
22. Compute Meenakshi daily salary.
23. Determine the minimum and maximum employee’s salaries.
24. Print the average annual salary.
25. Count the number of employees over 30.
26. Find out the department name having highest employee strength.
27. Find out the name and department name of the manager getting the
highest salary.
28. Concatenate employee name and employee no separated by a ‘,’ the
initial letter of the employee name should be in capital.
29. Find the position of ‘A’ in the names of all the employees.
30. Find the sum and average salary of given employees.
31. Display the details of all persons 3 letter names.
32. Display the name of all persons joined after ‘Smith’.
33. List the salaries available in dept no 10 or dept no 30 other than the
salaries available in the dept no 20.
Cycle Sheet – III

JOINS

1) Consider the employee database defined by the following schemas.


Employee (employee-name, street, city)
Works (employee-name, company-name, salary)
Company (company-name, city)
Manages(employee-name, manager-name)

Give an expression in SQL for each of the following queries.


a) Find the names of all employees who work for Fist Bank
Corporation.
b) Find the names and cities of residence of all employees who
work for First Bank Corporation.
c) Find the names, street address and cities of residence of all
employees who work for First Bank Corporation and earn more
than $10,000.
d) Find all employees in the database who live in the same cities
as the companies for which they work.
e) Find all employees in the database who live in the same cities
and on the same streets as do their managers.
f) Find all employees in the database who do not work for First
Bank Corporation.
g) Find all employees in the database who earn more than every
employee of Small Bank Corporation.
h) Find all employees who earn more than the average salary of all
employees of their company.
i) Find the company that has the most employees.
j) Find the company that has the smallest payroll.
k) Find those companies whose employees earn a higher salary,
on average, than the average salary at First Bank Corporation.
2. Consider the following relations:

Students (snum, name, major, leve, age)


Class (cname, meets_at, room, fid)
Faculty (fid, fname, deptid)
Enrolled(snum, cname)

Write the following queries in SQL. No duplicates should be printed in any


of the answers.
a) Find the names of all Juniors (level=JR) who are enrolled in a class
taught by I.Tech.
b) Find the age of the oldest students who is either a History major or
enrolled in a course taught by I. Tech.
c) Find the names of all classes that either meet in room R128 or have
five or more students enrolled.
d) Find the names of all students who are enrolled in two classes that
meet at the same time.
e) Print the level and the average age of students for that level, for each
level.
f) Print the level and the average age of students for that level, for all
levels except JR.
g) Find the names of students enrolled in the maximum number of
classes.
h) Find the names of students not enrolled in any class.
Cycle Sheet – IV

1. Create a PL/SQL block to accept an empno and display the salary of the
person.
2. Create a PL/SQL block to accept an empno and display the grade as
follows.
>5000 a
>4000 & <5000 b
<4000 c
3. Create a PL/SQL block to list all numbers between 1 and 100
4. Create table with 5 rows and 5 columns
5. To find the factorial of the given number using function
6. To find the Fibonacci of the given number using procedure
7. The ACCT_MAST table records the current balance for an account,
which is updated whenever, any deposits or withdrawals takes place. If the
withdrawal attempted is more than the current balance held in the account,
a user defined exception is raised displaying an appropriate error message.
Table name: ACCT_MAST
ACCT_NO CURBAL
SBI 15000
SA14 500
CA1 2000
8. Write a database trigger before insert for each row on the Bank (Table)
not allowing tranasactions on Sunday and Saturday.

Das könnte Ihnen auch gefallen