0% found this document useful (0 votes)
46 views38 pages

DBMS - Aman 2

The document describes experiments to be performed on database tables to demonstrate various SQL commands like creation, deletion, updating and altering of tables as well as applying constraints, operators, functions and writing procedures. The experiments involve creating sample tables, inserting and retrieving data from the tables, modifying the structure and data, applying various conditions to retrieve selective records and exploring integrity constraints.

Uploaded by

rojar90505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views38 pages

DBMS - Aman 2

The document describes experiments to be performed on database tables to demonstrate various SQL commands like creation, deletion, updating and altering of tables as well as applying constraints, operators, functions and writing procedures. The experiments involve creating sample tables, inserting and retrieving data from the tables, modifying the structure and data, applying various conditions to retrieve selective records and exploring integrity constraints.

Uploaded by

rojar90505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

AJAY KUMAR GARG ENGINEERING

COLLEGE,GHAZIABAD

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

PRACTICAL FILE

COURSE : B.Tech (AIML)


SEMESTER :V
SUBJECT : DBMS LAB
SUBJECT CODE : KCS-551

SUBMITTED BY SUBMITTED TO
Harsh Gupta Mr. Pronab Kumar Adhikari
(2100271640023)
INDEX

NAME OF
SI.
EXPERIM
No.
ENT
1 Application of Creation, Deletion, Insertion, Updation, Alter,
Destroy, RenameCommands
a. Create Table CLIENT_MASTER,
PRODUCT_MASTER,
SALESMAN_MASTER
b. Insert relevant data into the tables
c. Retrieve data from table CLIENT_MASTER,
PRODUCT_MASTER,
SALESMAN_MASTER
d. Update records in the tables CLIENT_MASTER,
PRODUCT_MASTER,
SALESMAN_MASTER
e. Delete records from tables CLIENT_MASTER,
PRODUCT_MASTER,
SALESMAN_MASTER
f. Create a new table with already existing table
g. Insert data into a new table from already existing table
h. Alter structure of the tables CLIENT_MASTER,
PRODUCT_MASTER,
SALESMAN_MASTER
i. Destroy a table along with its data
j. Rename SALESMAN_MASTER
k. Show the structure of the table product_master
2 Application of operators, date conversion functions:
a. Application of operator on a column
b. Application of operator and renaming of column
c. Use of AND operator
d. Use of OR
e. Use of BETWEEN
f. Use of NOT BETWEEN
g. USE of LIKE
h. USE of LIKE with OR
i. Use of IN
j. Use of NOT IN
k. Use of Conversion functions like TO_CHAR, TO_DATE
etc.
3 Execute the following queries:
a. The NOT NULL
b. The UNIQUE Constraint
c. The PRIMARY KEY Constraint
d. The FOREIGN KEY Constraint
e. The CHECK Constraint
f. Defining Integrity constraints in ALTER table command

4 Execute queries related to Group By and


Having Clause ontablesSALES_ORDER.

5 Execute Nested Queries on tables CLIENT_MASTER,


PRODUCT_MASTER,SALESMAN_MASTER,
SALES_ORDER,
SALES_ORDER_DETAILS
6 Execute queries related to Exists, Not Exists, Union,
Intersection, Difference,Join on tables
CLIENT_MASTER, PRODUCT_MASTER,
SALESMAN_MASTER, SALES_ORDER,
SALES_ORDER_DETAILS
7 Procedures, Functions & Packages:
a. Write a simple procedure to display a message “Good
Day to You”
b. Code a function to return the Square of a given number.
c. Create a package to include the following:
i. A named procedure to list the
Product_no of products with
Quantity_on_hand as 5 in
PRODUCT_MASTER table.

ii. A function which returns the max maximum


Quantity_on_handfora given product.
8 Write a TRIGGER to ensure that
CLIENT_MASTER TABLE does not
containduplicate of null values in CLIENT_NO
column.
9 Write a CURSOR to display list of clients in the
CLIENT_MASTER table.
10 Installing Oracle
11 Creating Entity-Relationship Diagram using case tools.
12 PL/SQL programming
Write a PL/SQL block code to print the squares of numbers upto
99.Write a PL/SQL block code to
insert data into tableCUSTOMER
Experiment-1
Program Name: Application of Creation, Deletion, Insertion, Updation, Alter,
Destroy,
Rename Commands
a. Create Table CLIENT_MASTER, PRODUCT_MASTER, SALESMAN_MASTER
b. Insert relevant data into the tables
c. Retrieve data from table CLIENT_MASTER, PRODUCT_MASTER,
SALESMAN_MASTER
d. Update records in the tables CLIENT_MASTER, PRODUCT_MASTER,
SALESMAN_MASTER
e. Delete records from tables CLIENT_MASTER, PRODUCT_MASTER,
SALESMAN_MASTER
f. Create a new table with already existing table
g. Insert data into a new table from already existing table
h. Alter structure of the tables CLIENT_MASTER, PRODUCT_MASTER,
SALESMAN_MASTER
i. Destroy a table along with its data
j. Rename SALESMAN_MASTER
k. Show the structure of the table product_master

Theory Concept: This program intends to demonstrate application of


variouscommandsused for data definition and data manipulation
language.

Implementation:

Q-a) Create the tables described below

Table Name : CLIENT_MASTER


Description : Used to store the client information
Table Name : PRODUCT_MASTER
Description : Used to store the product information
Table Name : SALESMAN_MASTER
Description : Used to store the salesman information working for the Company

Q-b) Insert data items into the tables created above


Ans : insert into client_master(client_no. , name , city , pincode , state)
values(‘&client_no.’
, ‘&name’ , ‘&city’ , ‘&pincode’ , ‘&state’);

Output: 5 rows

insertedinsert into

product_master

(product_no.,description,quantity_on_hand,cost_price,selling_price)
values(‘&product_no’,’&description’,’&quantity_on_hand’,’&cost_price’,’&selling_p
rice’);
Output: 3 rows created
Q-c) Retrieve the data from the following tables
a) select names from client_master ;
Output:

b) select description, cost_price, selling_price from product master ;


Output

c) select name from client_master where city = ’Varanasi’;


Output

d) Select the distinct city from client_master


Output

Q-d) Update the records in the tables above as follows

a) Change the city of client_no ‘C1’ to dhampur


b) Change the cost price from 250 to 500 in product_master;

Ans :
Q-e) Delete records in the table above as follows
Delete all records for the product_master table

Q-f) Create table New_client from client_master with the fields Client_no,
nameAns : create table new-client(client_no,name) as (select client_no,name
fromclient_master);

Output:Table created

Q-g) Alter the table structures as instructed

a) Add a column called Telephone_no of data type number and size = 10 to


theclient_master table
b) Change the size of the description column in product_master to 25
c) Drop the column Telephone_no from the table client_master
Ans:
a) alter table client_master add(telephone_number(10));

Output: Table altered

b) alter table client_master drop column telephone

Output: Table altered


Q-h) Destroy the table new_client along with its
dataAns:
Experiment- 2

Program Name:
Application of operators, date conversion functions:
a. Application of operator on a column
b. Application of operator and renaming of column
c. Use of AND operator
d. Use of OR
e. Use of BETWEEN
f. Use of NOT BETWEEN
g. USE of LIKE
h. USE of LIKE with OR
i. Use of IN
j. Use of NOT IN
k. Use of Conversion functions like TO_CHAR, TO_DATE etc.

Theory Concepts:
This experiment deals with commands of SQL which are used to print data
from a table with various conditions. It also deals with various in built
commands like max(), min(), sqrt(), round(), trim(), etc. The program
would print the current system date and time using the different
commands.

Implementation:
Computation on Tables:

a)Select product_no, description, selling_price * 0.05 from Product_master;


Output:

b)Select product_no, description, selling_price fromProduct_master where cost_price> 500


AND cost_price<1200;
Output:

c) Select client_no, name, city from client_master where pincode = 201014 OR pincode
=201009;
Output:
d)Select product_no, description, selling_price fromProduct_master
wherecost_priceBETWEEN 500 AND 700;
Output:

e)Select product_no, description, selling_price fromProduct_master


wherecost_price NOTBETWEEN 500 AND 700;
Output:

f) Select * from client_master where name like ‘s%’;


Output:

g)Select * from client_master where name like ‘S%’ OR name like ‘A%’;
Output:

h)CONVERSION FUNCTIONS:

1.Select to_date('09-08-1966') from dual;


Output:

2.Select add_months(sysdate,4) from dual;


Output:

3.Select last_day(sys date) from dual;


Output:

4.Select next_day('15-Feb-10', 'Wednesday') from dual;


Output:
Experiment- 3

Program Name: Execute the following queries:


a. The NOT NULL
b. The UNIQUE Constraint
c. The PRIMARY KEY Constraint
d. The FOREIGN KEY Constraint
e. The CHECK Constraint
f. Defining Integrity constraints in ALTER table command

Theory Concept:
This program intends to explore various constraints enforced on the
database like NOT NULL, UNIQUE constraint etc. Primary kay is an
attribute of table which is used to identify each row of the table uniquely.
Foreign key is used to reference other tables.

Implementation:

a.The NOT NULL Constraint

Q-1) Create table Employee with attributes eno, name, salary and the constraints that
eno and name cannot be NULL
Ans: create table employee(eno number NOT NULL, name varchar(20)
NOT NULL,salarynumber);
Output: Table created

Q-2) Insert data into the table Employee.Then Test the NOT NULL constraint
withappropriate data.
Ans:insert into employee_30 (eno,name,salary) values(1,'Amit',20000);
Output:1 row inserted

insert into employee (eno,name,salary) values(2,'Sumit',null);


Output:1 row inserted

Q-3) Select all records from Employee where salary is


NULLAns: select * from employee where salary is null;
Output:
b.The UNIQUE Constraint

Q-4) Create table Department with attributes dno, dname and no_of_employees and
theconstraint that dno and dname must be unique
Output:

Q-5) Insert records into the above table. Test the UNIQUE constraint
withappropriate data
Output:

insert into department (dno,name,no_of_employees) values(1,'AIML',20)


Output:** This query will give an error for violation of UNIQUE constraint

c.The PRIMARY KEY Constraint

Q6) Create table Project with attributes pno, pname, location and pno as
theprimary key
Output:

Q7) Insert into project appropriate records


Output:
insert into project (pno,pname,location) values (1,’Web Designing’, ‘Lab);
Output:** This query will give an error for violation of UNIQUE constraint

e.The CHECK Constraint

Q-11) Create table person with attributes ssno, name city such that all ssno have ‘C’ as
the first character, all names are entered in uppercase and city is either Delhi or
Mumbai or Bangalore
Ans:Create table person(ssnovarchar(3) CHECK(ssno LIKE
'C%'),name varchar(20)CHECK (name = upper(name)), city
varchar(20) CHECK (city IN('Delhi','Mumbai','Bangalore')));

insert into person values('C12','MAMTA','Mumbai');


Output:

insert into person values('C12','mamta','Mumbai');


Output:ERROR at line 1:
f)Defining Integrity Constraints in the Alter Table Command

Q-12) Alter table client_master to make client_no the primary


keyAns: alter table client_master ADD Primary key(client_no);
Output:

Q-13) Alter table client_master to drop the primary


keyAns: alter table client_master drop primary key;
Output:
Experiment- 4

Program Name:
Execute queries related to Group By and Having Clause on tablesSALES_ORDER.

Theory Concept:
The program aims to familiarize the user with grouping of data based on
conditions to ensurebetter usability of data.

Implementation:

GROUP BY
Q1) Create table sales_order with attributes product_no and Qty. Insert
recordsinto the table and find the total qty ordered for each product_no.
Ans: Create table sales_order (product_novarchar(10), Qty numbe(4));
Output: Table created.
insert into sales_order values(&product_no, &qty);
select* from sales_order;
Output:

Select product_no, sum(qty) from sales_order group by product_no;


Output:
HAVING clause

Q2) Find the total Qty for product_no ‘p1’ and ‘p2’ from the table sales_order
Ans:select product_no, sum(qty) from sales_order group by product_no having
product_no = 'p1' ORproduct_no = 'p2';

Output:
EXPERIMENT-5

Program Name:
Execute Nested Queries on tables CLIENT_MASTER,
PRODUCT_MASTER,SALESMAN_MASTER, SALES_ORDER,
SALES_ORDER_DETAILS

Theory Concept:
The program intends to familiarize nested queries so as to retrieve data
from a record byusing filtered data from another record.

Implementation:

Q1) Retrieve the order numbers, client names and their order dates
fromclient_master andsales_order tables.

Ans: Select order_no, order_date, name from sales_order,


client_master whereclient_master.client_no =
sales_order.client_no order by order_date; OUTPUT :

Q2) Retrieve the product numbers, description and total quantity ordered for each
product

Ans:Selectsales_order_details.product_no, description,
sum(qty_ordered) from sales_order_details, product_master where
product_master.product_no = sales_order_details.product_no group
by sales_order_details.product_no, description;OUTPUT :

Q3) Retrieve the names of employees and names of their respective managers
from theemployee table.
Ans: Select employee.name, employee.name from employee where
employee.manager_no =employee.employee_no;
OUTPUT : No rows found
UNION , INTERSECT and MINUS CLAUSE

Q1) Retrieve the salesman name in Mumbai whose efforts have resulted
intoatleast onesales transaction
Ans:Selectsalesman_no, name from salesman_master where city =
‘Mumbai’INTERSECT
Select salesman_master.salesman_no, name from salesman_master, sales_order
wheresalesman_master.salesman_no = sales_order.salesman_no;
OUTPUT :

Q2) Retrieve all the product numbers of non-moving items from the product_master
tableAns:Selectproduct_no from product_master
Minus
Select product_no from sales_order_details;
OUTPUT :

VIEWS

Q1) Create a view on salesman_master table for the


salesdepartment
Ans:Create view vw_sales as select * from salesman_master;
OUTPUT:

Q2) Create a view on client_master table


Ans:Create view vw_client as select name, address1, address2 , city,pincode
, state, bal_duefrom client_master;
OUTPUT:
Q3) Perform insert, modify and delete operations on the view created in
Q2Ans:
a) Insert into vw_client values(‘C001’, ‘Robert’, ‘AAAAAA’, ‘BBB’, ‘Delhi’, 2000000, ‘MMM’);
OUTPUT:

b)Delete from vw_client where client_no = ‘C001’;

OUTPUT:
Experiment-6

ProgramName:Execute queries related to Exists, Not Exists, Union,


Intersection, Difference, Join on tables CLIENT_MASTER,
PRODUCT_MASTER, SALESMAN_MASTER, SALES_ORDER,
SALES_ORDER_DETAILS
Theory Concept:
The program retrieves data from records by defining relation between
two tables so as toretrieve filtered records.

Implementation:
Correlated queries with EXISTS/NOT EXISTS clause

1) Select all products and order_no where order_status is ‘in Process’

2) Find all order_no for salesman rashmi.


Ans:Select order_no from sales_order where exists(select * from
salesman_master wheresalesman_master.saleman-no= sales_order-
salesman_no and name=’rashmi’);
Output :

Order_no
0003

3) Select all clients who have not placed any orders.


Ans:Select * from client_master where not exists(select * from
sales_order.client_no=client_master.client_no);
Output :
Union,Intersect and minus clause:

1) List all the clients and salesman and their names


Ans:Select client_no, name from client_master UNION select
salesman_no,name fromsalesman_master;
Output :

2) List all the clients and their names who are also salesman.
Ans:Select name from client_masterINTERSECT,select name from
salesman_master;
Output :
No rows selected
3) List all the clients who are not salesman.
Ans:Select name from client_master MINUS select name from salesman_master;
Output :

4) List all the clients who have placed orders


Ans:Select client_no from client_masterINTERSECT select client_no from
sales_order;
Output :
5) List all the clients who have not placed any order.

Ans:Select client_no from client_masterMINUS select client_no from sales_order;


Output :

6) Find all the clients and their names from city Ghaziabad who have delivery date of
theirorders as today.
Ans:Select client_no from client_master where city=’Ghaziazbad’
INTERSECT selectclient_no from sales_order where
delivery_date=’09-MAR-13’
Output :

Queries on Joins

1)List the product_no and description of products sold.


Ans:Select product_no, description from (product1 natural join sales_order_details)
Output :

2) Find the products which have been sold to ‘saumya’


Ans:Select product_no, description from (product1 natural join
sales_order details natural join sales_order natural join client_master)
where name=’saumya’;

3)Find the products and their quantities that will have to be delivered in the current
month. Ans:Select sales_order_detailsproduct_no, product1 ,description,
sum(sales_order_details, quantity_ordered) from sales_order_details, sales_order,
product1 where product1,
product_no=sales_order_details, product_no and sales_order,
order_no=sales_order_details,order_no and to_char (delivery_date,’mon-
yy’) = to_char(sysdate,’mon-yy’)group by sales_order_details, product_no,
product1, description ;
Output :
no rows selected

4)Find the names of client who have purchased ‘chair’


Ans:Select name from(client_master natural join sales_order natural join
sales_order_detailsnatural join product1) where description= ‘chair’;

Output :

5)List the orders for less than 5 units of sale of ‘chair’


Ans:Select product_no, order_no from (sales_order_details natural
join product1) where(description=’chair’ and qty_ordered<5);
Output :
EXPERIMENT-7

Program Name: Procedures, Functions & Packages:


a. Write a simple procedure to display a message “Good Day to You”
b. Code a function to return the Square of a given number.
c. Create a package to include the following:
A named procedure to list the Product_no of products with
Quantity_on_handas 5 in PRODUCT_MASTER table.
A function which returns the max maximum
Quantity_on_hand for a givenproduct.

Theory Concept:
The program would print the message using a procedure in .

Implementation:

Ans(a):
Ans(b):

Ans(c):
Experiment- 9

Program Name: Write a CURSOR to display list of clients in the


CLIENT_MASTERtable.

Theory Concept: The following example would illustrate the concept of


CURSORS. Wewill be using the CLIENT_MASTER table and display
records.

Implementation:
Experiment- 10

Program Name: Installing Oracle

Theory Concept: To install the software, you must use the Universal installer.

Implementation:

1. For this installation, you need either the DVDs or a downloaded version of the DVDs. In this
tutorial, you install from the downloaded version. From the directory where the DVD files
wereunzipped, open Windows Explorer and double-click on setup.exe from the \db\Disk1
directory.

2. The product you want to install is Database 11g. Make sure the product is selected and
click Next.

3. You will perform a basic installation with a starter database. Enter orcl for the Global Database
Name and for Database Password and Confirm Password. Then, click Next.
4. Configuration Manager allows you to associate your configuration information with
yourMetalink account. You can choose to enable it on this window. Then, click Next.

5. Review the Summary window to verify what is to be installed. Then, click Install.
6)The progress window appears.

7. The Configuration Assistants window appears.


8. Your database is now being created.

9. When the database has been created, you can unlock the users you want to use. Click OK.

10. Click Exit. Click Yes to confirm exit.


Experiment- 11

Program Name: Creating Entity-Relationship Diagram using case tools.

Theory Concept: Entity relationship diagram (ERD) is a kind of diagram


for presenting visually the structure of relational database. In this
experiment we will make use of ERD to model the database structure of a
simple bus route management system.

Implementation:
1. Start Visual Paradigm. Select a new workspace folder for this tutorial.

2. Select Project > New from the toolbar to create a project. Name the project as Bus
RouteManagement and confirm.

3. To create an ERD, select Diagram > New from the toolbar. In the New Diagram
window, select Entity Relationship Diagram and click Next. Enter Bus
RouteManagement as diagram name and click OK.

4. Let's start by creating the first entity Route. Select Entity in diagram toolbar and click

onthediagram to create an entity. Name the entityRoute and press Enter to confirm.

5. Create columns in Route. Let's start with a primary key. Right click on entity Route
andselect New Column from popup menu.

6. Enter +id : varchar(10) and press Enter. Note that the + sign means that the column is

aprimary key. Varchar is the column type and 10 is the length.

7. Enter fare : float and press Enter, then Esc to create another column.

8. Create entity Stop. A bus route has many bus stops, while a stop can be shared by many

routes. Therefore, there is a many-to-many relationship between Route and Stop. Place

themouse pointer over the Route entity. Drag out the Resource Catalog icon at top right.

9. Release the mouse button and select Many-to-Many Relationship -> Entity

fromResource Catalog.

10. Name the new entity Stop, You can see that a linked entity Route_Stop

isautomaticallycreated in between Route and Stop, with foreign key

added.
Final Entity-Relationship diagram is as follows:
Experiment- 12

Program Name:
PL/SQL programming
a. Write a PL/SQL block code to print the squares of numbers upto 99.
b. Write a PL/SQL block code to insert data into table CUSTOMER

Theory Concept:
The program would print the squares of numbers upto 99 using for loop and data
into tableCUSTOMER in pl/sql.

Implementation:
Ans (a):
Ans (b):
AN

You might also like