DBMS - Aman 2
DBMS - Aman 2
COLLEGE,GHAZIABAD
PRACTICAL FILE
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
Implementation:
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:
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
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:
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:
g)Select * from client_master where name like ‘S%’ OR name like ‘A%’;
Output:
h)CONVERSION FUNCTIONS:
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:
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
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:
Q6) Create table Project with attributes pno, pname, location and pno as
theprimary key
Output:
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')));
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:
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.
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
OUTPUT:
Experiment-6
Implementation:
Correlated queries with EXISTS/NOT EXISTS clause
Order_no
0003
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 :
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
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
Output :
Theory Concept:
The program would print the message using a procedure in .
Implementation:
Ans(a):
Ans(b):
Ans(c):
Experiment- 9
Implementation:
Experiment- 10
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.
9. When the database has been created, you can unlock the users you want to use. Click OK.
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
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
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