Download as pdf or txt
Download as pdf or txt
You are on page 1of 94

DATABASE

MANAGEMENT
SYSTEM

PRACTICAL FILE

Submitted by: Submitted to:


Raghav Grover Mrs. Preeta Rajiv
BCA-II(M) (2011-2014)
02213702011
Assignment – 1

Q1: Write down the steps along with snapshots to open a SQL session

 1. Open the Desktop

2. Go to start. Click on ‘All Programs’.

3. Select Oracle-orclient10g_home1

4. Then select application development from the various options available.

5. Next select SQL Plus.

6. An SQL Plus window appear which asks for the user name, password and host string.

7. Enter the user name as bca17, password as 123456 and host string as orcl.

8. Then the SQL is ready to be used.


Assignment – 2

Q. 1 Create Table:

EMPLOYEE

Empcode integer

Empname varchar2(25)

Address varchar2(30)

Gender char(1)

Grade char(2)

Deptcode char(3)

 Command to create table:

Q. 2. Create Table:
STUDENT

Roll_no integer,
Name varchar2(30)
Course char(3)
Address varchar2(30)
Email_id varchar2(20)
Phone_no number(12)
Father_name varchar2(20)
Marks_X integer
Marks_XII integer

 Command to create table:

Q. 3. Create Table:

BOOK (Bookno , Title, Author, Publisher, Edition, Price)


 Command to create table:

Q. 4. Create Table:

SPORTS_CLUB (Coach_id, coachname, sport, age, dateofapplication, gender)

 Command to create table:


Assignment – 3

Q. 1 Create Table:

Flight (flightcode, flight_desc, source, destination)

Insert 2 records in the above tables created

Use datatypes :

Varchar2, Number, Date, char wherever required

 Command to create table and insert values to the table:


Q.2 Create Table:

Order(Orderno, Orderdesc, quantity, price)

Insert 2 records in the above tables created

Use datatypes :

Varchar2, Number, Date, char wherever required

 Command to create table and insert values to the table:


Q.3 Create Table:

Job (JobID, Jobdescription, Allocated_on, Empname)

Insert 2 records ‘interactively’ in the above tables created

Use datatypes :

Varchar2, Number, Date, char wherever required

 Command to create table and insert values to the table:


Q.4 Create Table:

Result (Rollno, Name, Percent, Course, Sem )

Insert 2 records ‘interactively’ in the above tables created.

Use datatypes :

Varchar2, Number, Date, char wherever required

 Command to create table and insert values to the table:


Assignment – 4

Q. 1 Create Table:

BILL (Bill_no, Bill_date, Amount, Tax, Total_amt)

Queries:
(i) Display all the bill details of ‟24-jan-12‟

(ii) Display the bill details where total amount is greater than 6000.

(iii) Display the bill details where total amount is less than 500

 Command to create table:


Insertion of values:
Queries performed:

(i) Display all the bill details of ‟24-jan-12‟

(ii) Display the bill details where total amount is greater than 6000.

(iii) Display the bill details where total amount is less than 500
Q. 2 Create Table:

CAR(Regn_no, Make, Colour, Model, Owner)

Queries:

(i)Display the owners who does not own a „Maruti‟

(ii)Display the car details of car make „Hyundai‟

(iii)Display model and owners from CAR

(iv)Display the car details whose car colour is „RED‟

 Command to create table:


Insertion of values:
Queries performed:
Q.3 Create a table:

SUPPLIER(Sup_code, Sup_name, Address, City, Phone_no)

Queries:

(i)Display all the city from Supplier

(ii)Display all the city from supplier with DISTINCT keyword

(iii)Display the details of supplier „JANAK SPARE PARTS‟

 Command to create table:


Insertion of values:
Queries Performed:

(i)Display all the city from Supplier

(ii)Display all the city from supplier with DISTINCT keyword

(iii)Display the details of supplier „JANAK SPARE PARTS‟


Assignment – 5

Q.1 To perform queries for the table “BILL” using various DDL,DML and DQL commands.

(i) Add a column „number_of_items‟ to BILL table.

(ii) Rename the table „BILL‟ to „BILL_DETAILS‟.

(iii) Update the bill amount of 24-JAN-12.

(iv) Display the bill no. and total amount multiplied by 3.

 Queries performed:
(i) Add a column „number_of_items‟ to BILL table
(ii) Rename the table „BILL‟ to „BILL_DETAILS‟.
(iii) Update the bill amount of 24-JAN-12.
(iv) Display the bill no. and total amount multiplied by 3.
Q.2 To perform queries for the table “CAR” using various DDL,DML and DQL commands.

(i) Rename the table „CAR‟ to „CAR_INFORMATION‟

(ii) Delete all the details of car „Hyundai‟

(iii) Update the car color from „RED‟ to „METTALIC_RED‟

(iv) Display the car details in ascending or descending order of colour.

 Table „CAR‟:

Queries Performed:

(i) Rename the table „CAR‟ to „CAR_INFORMATION‟


(ii) Delete all the details of car „Hyundai‟

(iii) Update the car color from „RED‟ to „METTALIC_RED‟

(iv) Display the car details in ascending or descending order of colour.

After Updating:
Q.3 To perform queries for the table “SUPPLIER” using various DDL, DML and DQL
commands.

(i) Add a column „Country‟ to SUPPLIER Table

(ii) Delete all the details of supplier „JANAK SPARE PARTS‟

(iii) Display the supplier details grouped CITY wise.

 Table „SUPPLIER‟:
Queries Performed:

(i) Add a column „Country‟ to SUPPLIER Table

(ii) Delete all the details of supplier „JANAK SPARE PARTS‟

(iii) Display the supplier details grouped CITY wise.


Assignment – 6

Q.1 To perform queries for the table “BILL” .

(i) Display the bill details having bill amount less than 50000 or bill date with

28-jan-12.

(ii) Find all the bills where no. of items is not null.

(iii) Find all the bill details where Bill amount is between 1000 and 5000.

 Queries performed:

(i) Display the bill details having bill amount less than 50000 or bill date with

28-jan-12.

(ii) Find all the bills where no. of items is not null.
(iii) Find all the bill details where Bill amount is between 1000 and 5000.

Q.2 To perform queries for the table “CAR” .

(i) Display the car details of cars HYUNDAI and MARUTI


(ii) Find the list of cars whose owners have their names starting with „J‟ or „A‟ or
„S‟

(iii) Find all the car details where car names have „u‟ in between.

(iv) Find the car details where car make not in the list [swift, innova, scorpio.

 Table „CAR‟:

Queries Performed:

(i) Display the car details of cars HYUNDAI and MARUTI

(ii) Find the list of cars whose owners have their names starting with „J‟ or „A‟ or
„S‟
(iii) Find all the car details where car names have „u‟ in between.

(iv) Find
the car
details
where car
make not
in the list
[swift,
innova,
scorpio.
Q.3 To perform queries for the table “SUPPLIER”.

(i) Display the supplier details of NEW DELHI or MUMBAI

(ii) Find all the suppliers whose name starts with D

(iii) Find all the supplier details where country is not given

 Table „SUPPLIER‟:
Queries Performed:

(i) Display the supplier details of NEW DELHI or MUMBAI.

(ii) Find all the suppliers whose name starts with D.

(iii) Find all the supplier details where country is not given
Assignment – 7

Q.1 Create the following schema:

ITEM(Item_code, Item_desc, Year_of_mfg, Price, Stock_on_hand)

Note: Item_code will be PRIMARY KEY,

Item_desc will be NOT NULL

Add some records to these schema:

Add 2 records with same Item_code.

Add records with Item_desc as blank.

Record the error.

(i) Display all the items manufactured in the year 2000 and 2010.

(ii) Display all the items whose price is between 500 and 1000.

(iii) Get the item details with price of every item added with 25.

(iv) Get the item details where the Year_of_mfg is null.

(v) List the item with the minimum price

(vi) List the item with the maximum price

 Creating the table:


Adding records to these schema:

Adding 2 records with same Item_code:


Adding record with Item_desc as blank:

 Queries performed:
(i) Display all the items manufactured in the year 2000 and 2010.

(ii) Display all the items whose price is between 500 and 1000.

(iii) Get the item details with price of every item added with 25.
(iv) Get the item details with price of every item added with 25.

(v) List the item with the minimum price

(vi) List the item with the maximum price


Q.2 Create the following schema:

PATIENT(Patient_#, Patient_first_name, Patient_last_name, Address, Phone_no)

Note: Patient_no. will be PRIMARY KEY

Patient_first_name, Phone_no will be NOT NULL

Add some records to these schema:

Add 2 records with same Patient_no.

Record the error.

(i) Give the details of all patients whose first name starts with S.

 Creating the table:

Adding records to the schema:


Adding record with same Patient_no:
 Queries performed:

(i) Give the details of all patients whose first name starts with S.

Q.3 Create the following schema:

TEST(Test_code, Testname, Doctor_name, Test_date)

Note: Test_code will be PRIMARY KEY,

Testname will be NOT NULL

Add some records to these schema:

Add 2 records with same Test_code.

Add records with Testname as blank.

Record the error.

(i) Display all the test details except ECG and Liver Check.

(ii) Get the test details in descending order of Doctor_name.

(iii) Get the test details where the test_date is not null.
 Creating the table:

Adding records to the schema:


Adding record with same Test_code:
Adding record with Testname as blank:

 Queries performed:

(i) Display all the test details except ECG and Liver Check.
(ii) Get the test details in descending order of Doctor_name.

(iii) Get the test details where the test_date is not null.
Assignment – 8

Q.1 To perform queries for the table “ITEM” using Aggregate Functions and DML
commands.

(i) Find the total price of all items in the ITEM table.

(ii) Change the item description and Stock on hand for the items manufactured in
the year 2010.

 Queries performed:

(i) Find the total price of all items in the ITEM table.

(ii) Change the item description and Stock on hand for the items manufactured in
the year 2010.

Q.2 To perform queries for the table “PATIENT” using Aggregate Functions and
DML commands.
(i) Get the number of patients whose first starts with S.

 Queries performed:

(i) Get the number of patients whose first starts with S.

Q.3 To perform queries for the table “TEST” using Aggregate Functions and DML
commands.

(i) Get the number of rows in the TEST table.

(ii) Delete all the records of a particular test.


 Queries performed:

(i) Get the number of rows in the TEST table.

(ii) Delete all the records of a particular test.


Assignment – 9

Q.1 To perform queries for the table “ITEM” ,”PATIENT” and ”TEST” by the use
of different functions and to display the structure of DUAL TABLE.

(i) Get the count of unique patients from PATIENT table

(ii) Get the average price of items from ITEM table

(iii) Get the length of firstnames of all the patients.

(iv) Display the last names of patients in uppercase and lowercase.

(v) Display the patients names with 2 letters trimmed from left side

(vi) Display the patients names with 2 letters trimmed from right side.

(viii) Get the prices of items rounded off to 1 decimal place.

(ix) Get the prices of items truncated to 1 decimal place.

(x) Get the firstname and lastname of all patients together.

(xi) Get the part of item descriptions of items. (SUBSTR())

(xii) Get the modulus, power, sign and square root of numbers and display the
output.

 Queries performed:

(i) Get the count of unique patients from PATIENT table


(ii) Get the average price of items from ITEM table

(iii) Get the length of firstnames of all the patients.

(iv) Display the last names of patients in uppercase and lowercase.


(v) Display the patients names with K letter trimmed from left side

(vi) Display the patients names with letters trimmed from right side.

(viii) Get the prices of items rounded off to 1 decimal place.


(ix) Get the prices of items truncated to 1 decimal place.

(x) Get the firstname and lastname of all patients together.

(xi) Get the part of item descriptions of items. (SUBSTR())


(xii) Get the modulus, power, sign and square root of numbers and display the
output.
Assignment – 10

Q.1 To create the table “HOTELGUEST” (with no constraints).

HOTELGUEST(GuestID, Guestname, Checkindate, Address, City, PhoneNo,


EmailID)

ADDING CONSTRAINTS USING ALTER TABLE COMMAND.

To perform queries:

(i) Include „NOT NULL‟ constraints to Guestname, Address.

(ii) Alter the table to add Primary Key for column „ GuestID‟.

(iii) Include „UNIQUE‟ constraint to EmailID.

(iv) Add the constraint „CHECK‟ to the column „City‟ as „Delhi‟.

Now add some records which violate these constraints and note the error.

 Creation of table:
 Queries performed:

(i) Include „NOT NULL‟ constraints to Guestname, Address.

(ii) Alter the table to add Primary Key for column „ GuestID‟.
(iii) Include „UNIQUE‟ constraint to EmailID.

(iv) Add the constraint „CHECK‟ to the column „City‟ as „Delhi‟.

Adding records to the table:


Adding some records which violate the constraints:

Violating PRIMARY KEY constraint:

Violating NOT NULL constraint :


Violating UNIQUE constraint :

Violating CHECK constraint :


Assignment – 11

Q.1 To create the tables “COURSE” and “STUDENT”.

COURSE (Course_Code, CourseName )

PRIMARY KEY (Course_Code)

STUDENT (RollNo, Name, Address, Gender, Phonenumber, EmailID,


Course_code)

PRIMARY KEY (RollNo, Name)

(i) ADD FOREIGN KEY „Course_code‟ to the STUDENT TABLE (with ON


DELETE CASCADE)

(ii) Add some records in the STUDENT Table.

(iii) Delete the details of course „LLB‟. After that check records of both tables.

 Creation of tables:
(i) ADD FOREIGN KEY „Course_code‟ to the STUDENT TABLE (with ON
DELETE CASCADE).

(ii) Add some records in the STUDENT Table.


Adding some records to the COURSE table:
(iii) Delete the details of course „LLB‟. After that check records of both tables.

 Before Deletion:

 After Deletion:
Assignment – 12

Q.1 To perform queries for the table “STUDENT” using GROUP BY CLAUSE.

(i) Find the total number of students in different courses.

(ii) Create a view on STUDENT for students studying in course „BCA‟.

 Queries performed:

(i) Find the total number of students in different courses.

(ii) Create a view on STUDENT for students studying in course „BCA‟.

Q.2 To create the table “SUBJECT”.


Subject_code (Primary Key)

Subject_name (not null)

Credits (default „0‟)

Course_code (references course_code in COURSE)

Now perform the following queries:

(i) Find the total number of subjects.

(ii) Add a record for a course not in COURSE table.

(iii) Find the sum of credits, average of credits for different courses.

(iv) Find the subject having the maximum credits for course „BCA‟

(v) Create a view on SUBJECT selecting Subject_code, Subject_name and


Course_code.

 Creation of table:

Adding FOREIGN KEY constraint and references to the table:


Inserting values to the table:
Table “SUBJECT”:

Queries performed:

(i) Find the total number of subjects.

(ii) Add a record for a course not in COURSE table.


(iii) Find the sum of credits, average of credits for different courses.

 For course „BCA‟, Course code =1.

 For course „LLB‟, Course code =3

(iv) Find the subject having the maximum credits for course „BCA‟.
(v) Create a view on SUBJECT selecting Subject_code, Subject_name and
Course_code.
Assignment – 13
Revision Exercise

Q.1 To create the table “LOAN”.

Loan_account_no primary key


Loan_amount
Interest_rate between 4 and 12
Loan_type can take only values „fixed‟ and „float‟
Loan_period

Add records in both the tables.

Now perform the following queries:

(i) Find the total loan amount.

(ii) Calculate the simple interest of every loan account.

 Creation of table:

Adding records to the table:


Describing the table:
Queries performed:

(i) Find the total loan amount.

(ii) Calculate the simple interest of every loan account.

Q.2 To create the table “CUSTOMER”.

Cust_code primary key, check value between 1 & 100


Cust_firstname not null
Cust_lastname not null
Address
Phone_no
EmailID unique
Cust_loan_account references Loan_account_no of LOAN TABLE.

Add records in both the tables.

Now perform the following queries:

(i) Find the customers whose phone_no is blank.

(ii) Find all the customers whose firstname has „a‟ in between.

(iii) Find the list of customers with their firstname and lastname together.

 Creation of table:

Adding records to the table:


Table Customer:
Describing the table:

Queries performed:

(i) Find the customers whose phone_no is blank.

(ii) Find all the customers whose firstname has „a‟ in between.
(iii) Find the list of customers with their firstname and lastname together.
Assignment – 14
Revision Exercise

Q.1 To perform queries for the tables “LOAN” and “CUSTOMER”.

(i) Display customer names along with the length of the customer‟s firstnames.

(ii) Find all details of loans above 5 years or those loans with Fixed type.

(iii) Get the sum, average, maximum of loan amount with sum and average
rounded to 1 decimal place.

(iv) Get the details of customers „Sharma‟ , „Verma‟, „Paul‟, „Mehta‟

(v) Update the loan details of fixed type with loan period to 15.

(vi) Get the customer details of „Sharma‟ with customer code having one character
less from the left.

(vii) Get the Address of the customers with only a part of it.

(viii) Delete the details of loan whose interest rate is 6.

 Queris performed:

(i) Display customer names along with the length of the customer‟s firstnames.

(ii) Find all details of loans above 5 years or those loans with Fixed type.
(iii) Get the sum, average, maximum of loan amount with sum and average
rounded to 1 decimal place.

(iv) Get the details of customers „Sharma‟ , „Verma‟, „Paul‟, „Mehta‟.

(v) Update the loan details of fixed type with loan period to 15.
(vi) Get the customer details of „Sharma‟ with customer code having one character
less from the left.

(vii) Get the Address of the customers with only a part of it.

(viii) Delete the details of loan whose interest rate is 6.


Assignment – 15

Q.1 To perform queries for the tables “LOAN” and “CUSTOMER”.

INNER JOINS:

(i) Get the Loan details of customers whose name starts with „A‟.

(ii) Get the customer‟s firstname, lastname, address and phone number who have
taken a loan.

(iii) Get the loan_account_no, amount, type, customer‟s code, firstname and
lastname.

(iv) Get the loan details of customers „Sharma‟, „Verma‟.

OUTER JOINS:

(v) Get all the LOAN records irrespective of whether customers have taken the
particular loans or not. (left outer join)

(vi) Get all the CUSTOMER records irrespective of whether customers have taken
loans or not. (right outer join)

(vii) Get the Cartesian product of LOAN AND CUSTOMER.

 Queries performed:
(i) Get the Loan details of customers whose name starts with „A‟.
(ii) Get the customer‟s firstname, lastname, address and phone numbers who have
taken a loan.

(iii) Get the loan_account_no, amount, type, customer‟s code, firstname and
lastname.

(iv) Get the loan details of customers „Sharma‟, „Verma‟.


OUTER JOINS:

(v) Get all the LOAN records irrespective of whether customers have taken the
particular loans or not. (left outer join)

(vi) Get all the CUSTOMER records irrespective of whether customers have taken
loans or not. (right outer join)
(vii) Get the Cartesian product of LOAN AND CUSTOMER.
Assignment – 16

Q.1 To perform queries on UNION, INTERSECT, MINUS for the tables


“LOAN” and “CUSTOMER”.

(i) Get all the Loan numbers from both the LOAN & CUSTOMER table.

(ii) Get the Loan numbers common in both the tables.

(iii) Get the loan numbers which have not been allocated to customers.

CREATING INDEX

(i) Create an index on LOAN table on the Loan number.

(ii) Create an index on the CUSTOMER table on customer‟s first and last name.

 Queries performed:

(i) Get all the Loan numbers from both the LOAN & CUSTOMER table.
(ii) Get the Loan numbers common in both the tables.

(iii) Get the loan numbers which have not been allocated to customers.

CREATING INDEX

(i) Create an index on LOAN table on the Loan number.


(ii) Create an index on the CUSTOMER table on customer‟s first and last name.
Assignment – 17

Q.1 To perform queries on Joins and Nested query and to create the following
tables.
DEPT_DETAILS(Deptno, Deptname, Managername)
Primary Key - Deptno

EMP_DETAILS(Empcode, Empname, Address, Salary, Deptcode)


Primary Key – Empcode
Foreign Key – Deptcode referencing DEPT_DETAILS(Deptno)

DEPENDENT(Empcode, Dependentname, Age)


Foreign Key – Empcode referencing EMP_DETAILS(Empcode)

Queries:
(i) Get the details of employees whose salary is less than the average salary of
employees.
(ii) Get the details of employees whose salary is more than the average salary of
employees.
(iii) Get the details of employees whose salary is more than the salary of some of
the employees of „Marketing‟ dept.
(iv) Get the details of employees whose salary is more than the salary of all the
employees of „Marketing‟ dept.
(v) Get the details of employees who have at least one dependent.
(vi) Get the details of employees who have no dependents.
(vii) Get the details of employees who work in „Marketing‟ dept.
(viii) Get the sum, max, min, avg of salaries of employees of „Marketing‟ dept.
(ix) Get the count of employees in the „Marketing‟ dept.

 Creation of tables:
“DEPT_DETAILS”:

“EMP_DETAILS”:

“DEPENDENT”:
Table “DEPT_DETAILS”:

Table “EMP_DETAILS”:

Table “DEPENDENT”:
Queries performed:
(i) Get the details of employees whose salary is less than the average salary of
employees.

(ii) Get the details of employees whose salary is more than the average salary of
employees.
(iii) Get the details of employees whose salary is more than the salary of some
of the employees of „Marketing‟ dept.

(iv) Get the details of employees whose salary is more than the salary of all the
employees of „Marketing‟ dept.
(v) Get the details of employees who have at least one dependent.

(vi) Get the details of employees who have no dependents.

(vii) Get the details of employees who work in „Marketing‟ dept.


(viii) Get the sum, max, min, avg of salaries of employees of „Marketing‟ dept.

(ix) Get the count of employees in the „Marketing‟ dept.

You might also like