0% found this document useful (0 votes)
38 views20 pages

BCS-551 DBMS - 2024-25

dmbs

Uploaded by

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

BCS-551 DBMS - 2024-25

dmbs

Uploaded by

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

SI. No.

NAME OF EXPERIMENT
1 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
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 on tables


SALES_ORDER.

5 Installing Oracle
Experiment-1

ProgramName: 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 various commands


used 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

Column Name Data Type Size


Client_no Varchar2 6
Name Varchar2 20
Address1 Varchar2 30
Address2 Varchar2 30
City Varchar2 15
Pincode Number 6
State Varchar2 15

Table Name : PRODUCT_MASTER


Description : Used to store the product information

Column Name Data Type Size


Product_no Varchar2 6
Description Varchar2 20
Quantity_on_hand Number 8
Reorder_level Number 8
Cost_price Number 8,2
Selling_Price Number 8,2

Table Name : SALESMAN_MASTER


Description : Used to store the salesman information working for the Company

Column Name Data Type Size


Salesman_no Varchar2 6
Name Varchar2 20
Address1 Varchar2 30
Address2 Varchar2 30
City Varchar2 15
Pincode Number 6
State Varchar2 15
Date_of_joining Date
Salary Number 8,2

Ans:create table client_master(client_no. varchar(6), name varchar(20), city varchar(15),


pincode number(6), state varchar(5));
create table product_master(product_no. varchar(6), description varchar(20),
quantity_on_headnumber(8), cost price number(8,2), selling price number(8,2));
create table SALESMAN_MASTER(salesman_novarchar(6), name varchar(20),address1
varchar(30), address2 varchar(30), city varchar(15), pincode number(6), state varchar(15),
date_of_joining date, salary number(8,2));
Output: Table created

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’);
Client_no Name City Pincode State
3 Akshita Ghaziabad 23456 UP
4 Dhawal Ghaziabad 24364 UP
5 Akansha Dhampur 246761 UP
6 Divya Hapur 35498 UP

Output: 4 rows created

insert into product_master


(product_no.,description,quantity_on_hand,cost_price,selling_price)
values(‘&product_no’,’&description’,’&quantity_on_hand’,’&cost_price’,’&selling_price’);
Product no. Description quantity_on_hand cost_price selling_price
1 Chair 5 1000 1250
2 Table 5 5000 6000

Output: 2 rows created

Q-c) Retrieve records from the above tables as follows


a) Find out the names of all the clients
b) Retrieve the entire contents of the client_master table
c) Retrieve description, cost_price and selling_price from product master
d) Retrieve clients from client_master table who live in ’Dhampur’

e) Retrieve distinct city from client_master table


f) Retieveproduct_no., description and cost_price from product_masterwhich are
ordered by cost_price.

Ans:
a) select name from client_master ;
Output:
NAME
--------
Akshita
Dhawal
Akansha
Divya

4 rows selected

b) select * from client_master ;


Output:
Client_no Name City Pincode State
3 Akshita Ghaziabad 23456 UP
4 Dhawal Ghaziabad 24364 UP
5 Akansha Dhampur 246761 UP
6 Divya Hapur 35498 UP

4 rows selected

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


Output:
DESCRIPTION COST_PRICE SELLING_PRICE
------------------------------------------------------------------
Chair 1000 1250
Table 5000 6000

2 rows selected

d) select name from client_master where city = ’Dhampur’;


Output:
NAME
--------
Akansha
1 row selected

e) select distinct city from client_master ;


Output:
CITY
------------
Ghaziabad
Dhampur
Hapur

3 row selected

f) select product_no., description, cost_price from product_master order by cost_price ;


Output:
Product No. Description Cost Price
4 Mirror 250
1 Chair 1000

2 rows selected

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 :
a) Update client-master set city=’Noida’ where city=’Dhampur’;

Output:1 row selected


b) Update product_master
set cost _price=500 where cost _price=250;

Output: 1 row updated

Q-e) Delete records in the table above as follows


Delete all records for the product_master table
Ans:
Delete from product_master;

Output: 5 rows deleted

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

Q-g) Insert into table new_client data from table client_master where city = ‘Hapur’
Ans: insert into new_client select client_no.,name from client-master where city=’Hapur’;
Output:
Client_no. Name
6 Divya

1 row created

Q-h) Alter the table structures as instructed

a) Add a column called Telephone_no of data type number and size = 10 to the
client_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 created
b) alter table product_master modify(description varchar(25));

Output:Table created
c) alter table client_master drop column telephone_no;

Output:Table created

Q-i) Destroy the table new_client along with its data


Ans:
Drop table new_client;
Output:Table dropped

Q-j) Change the name of the product_master to products


Ans:
renameproduct_master to products;
Output:Table renamed

Q-k) Show the structure of the table product_master


Ans :
Describe product1
Output:
Column Description
Product_no. Varchar(6)
Description Varchar(20)
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:
PRODUCT_NO DESCRIPTION SELLING_PRICE*0.05
1 Chair 62.5
2 Table 300

b)Select product_no, description, selling_price * 0.05 new_price from Product_master;


Output:
PRODUCT_NO DESCRIPTION NEW_PRICE
1 Chair 62.5
2 Table 300

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


ANDcost_price<700;
Output:
No rows selected

d)Select client_no, name, city from client_master where pincode = 201001 ORpincode =
201009;
Output:
CLIENT_NO NAME CITY
3 Akshita Ghaziabad

e)Select product_no, description, selling_price fromProduct_master where


cost_priceBETWEEN 500 AND 700;
Output:
PRODUCT_NO DESCRIPTION SELL_PRICE
4 mirror 300

f)Select product_no, description, selling_price fromProduct_master where


cost_priceNOTBETWEEN 500 AND 700;
Output:
PRODUCT_NO DESCRIPTION SELLING_PRICE
1 Chair 1250
2 Table 6000

g)Select * from client_master where name like ‘ja%’;


Output:
No rows selected

h)Select * from client_master where name like ‘_r%’ OR name like ‘_h%’;
Output:
CLIENT_NO NAME CITY PINCODE STATE
4 Dhawal Ghaziabad 24364 UP

i)Select from client_masterclient_no, name, city where name IN(‘Ajay’, ‘Vijay’, ‘Amit’);
Output:
No rows selected

j)Select from client_masterclient_no, name, city where name NOT IN(‘Ajay’, ‘Vijay’,
‘Amit’);
Output:
CLIENT_NO NAME CITY
3 Aksita Ghaziabad
4 Dhawal Ghaziabad
5 AkanshaDharampur

k)CONVERSION FUNCTIONS:

1.Select to_date('30-Sep-1966') from dual;


Output:
TO_DATE(’30-SEP-1966)
30-Sep-66

2.Selectadd_months(sysdate,4) from dual;


Output:
ADD_MONTHS(SYSDATE,4)
13-Jun-13
3.Select last_day(sysdate) from dual;
Output:
LAST_DAY(SYSDATE)
28-Feb-13

4.Select months_between('15-Feb-10','15-Jun-10') from dual;


Output:
MONTHS_BETWEEN('15-Feb-10','15-Jun-10')
-4

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


Output:
NEXT_DAY('15-Feb-10', 'Wednesday')
17-Feb-10
Experiment- 3

ProgramName: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,salary
number);
Output:
Table created

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

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


Output:1 row inserted

insert into employee (eno,name,salary) values(null,'Amit',20000);


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

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


Ans: select * from employee where salary is null;
Output:
eno name
2 Sumit
1 row selected
b.The UNIQUE Constraint

Q-4) Create table Department with attributes dno, dname and no_of_employees and
the constraint that dno and dname must be unique
Ans:create table department (dno number UNIQUE,dnamevarchar(20) UNIQUE,
No_of_employees number);
OR
create table department (dnonumber,dnamevarchar(20) UNIQUE, No_of_employees
number) UNIQUE(dno);
Output: Table created

Q-5) Insert records into the above table. Test the UNIQUE constraint with
appropriate data
Ans: insert into department (dno,dname,no_of_employees) values(1,'EC',20);
Output: 1 row inserted

insert into department (dno,name,no_of_employees) values(1,'EC',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 the
primary key
Ans: create table Project (pnonumber,pnamevarchar(20),location varchar(20),PRIMARY
KEY(pno));
OR

create table Project (pno number PRIMARY KEY ,pnamevarchar(20),location varchar(20));


Output: Table created

Q7) Insert into project appropriate records


Ans: insert into project (pno,pname,location) values (1,’Web Designing’, ‘Lab);
Output:1 row inserted

insert into project (pno,pname,location) values (1,’Web Designing’, ‘Lab);


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

d.The FOREIGN KEY Constraint

Q8) Create table works_on with attributes eno, pno and hours where eno is foreign
key referencing eno from Employee table and pno is the foreign key referencing pno
from Project Table. Let {eno,pno} be the primary key for table Works_on
Ans: create table works_on(eno number REFERENCES Employee, pno number
REFERENCES Project, Hours number ,PRIMARY KEY(eno,pno));
Output: Table created

Q9) Insert appropriate records into the Works_on Table


Ans: Insert into Works_onvalues(1,2,30);
delete from employee where eno = 1;
Output: ** Error ORA-02292: integrity constraint (SCOTT.SYS_C003014) violated -
child record found

Q-10) Select appropriate records from the table Works_on by referencing the table
Employee and Project
Ans:select employee.eno,employee.name,project.pno,project.pname,works_on.hours from
works_on,employee,project
where (works_on.eno = employee.eno and works_on.pno = project.pno);
Output:
ENO NAME PNO PNAME HOURS
---- -------------------- ---------- -------------------- ----------
2 Amit 1 asd 8
2 Amit 2 sjxks 9
1 SAmit 1 asd 23
1 SAmit 2 sjxks 30
4 rows selected

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:1 row created

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 key


Ans: alter table client_master ADD Primary key(client_no);
Output:
Table Altered

Q-13) Alter table client_master to drop the primary key


Ans: alter table client_master drop primary key;
Output:
Table Alterted
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 ensure
better usability of data.

Implementation:

GROUP BY
Q1) Create table sales_order with attributes product_no and Qty. Insert records
into 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:
PRODUCT_NO QTY
---------- ----------
p1 12
p2 112
p1 9
p2 23
p3 23
p3 23

6 rows selected.

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


Output:
PRODUCT_NO SUM(QTY)
---------- ----------
p1 21
p2 135
p3 46
3 rows selected.

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
havingproduct_no = 'p1' OR product_no = 'p2';

Output:
PRODUCT_NO SUM(QTY)
---------- ----------
p1 21
p3 46

2 rows selected
Experiment- 5

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 were
unzipped, 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 your
Metalink 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.

You might also like