0% found this document useful (0 votes)
12 views11 pages

Lab Mannual Part 2 DBMS

The document outlines the curriculum for a Database Management System Lab course at Maharishi University of Information Technology, detailing various experiments and objectives related to SQL queries and database management. It includes tasks such as installing databases, creating tables, writing SQL statements, and performing operations like joins, unions, and subqueries. Each experiment focuses on different aspects of SQL, providing practical exercises for students to enhance their understanding of database systems.

Uploaded by

sonukbs123
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)
12 views11 pages

Lab Mannual Part 2 DBMS

The document outlines the curriculum for a Database Management System Lab course at Maharishi University of Information Technology, detailing various experiments and objectives related to SQL queries and database management. It includes tasks such as installing databases, creating tables, writing SQL statements, and performing operations like joins, unions, and subqueries. Each experiment focuses on different aspects of SQL, providing practical exercises for students to enhance their understanding of database systems.

Uploaded by

sonukbs123
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/ 11

Maharishi University of Information Technology

Name of the faculty: Mr. Dhananjay Kumar Yadav


Course : B.Tech
Year/Semester: III Subject code:BCES-313
Session: 2023-24
Subject Name: Database Management System Lab

List of Experiment
1. Installing oracle/ MYSQL
2. Creating Entity-Relationship Diagram using case tools.
3. Writing SQL statements Using ORACLE /MYSQL:
a) Writing basic SQL SELECT statements.
b) Restricting and sorting data.
c)Displaying data from multiple tables.
d)Aggregating data using group function.
e) Manipulating data.
e) Creating and managing tables.
4. Write SQL queries using logical operators (=, <, >, etc.)
5. Write SQL queries using SQL operators (between..end, IN(List), Like, IS NULL and also
with negating expressions.
6. Write SQL query using character, number and date data types.
7. Write SQL queries using group by and having clause.
8. Write SQL queries for UNION, INTERSECT and MINUS.
9. Write SQL queries for extracting data from more than one table (EQUI JOIN, NON EQUI
JOIN, Outer Join).
10. Write SQL queries for sub queries, nested queries.
Maharishi University of Information Technology

Experiment No. 3
Objective: Writing SQL statements Using ORACLE /MYSQL:

a) Writing basic SQL SELECT statements.


CREATE TABLE Student_Records
(
Student_Id Int PRIMARY KEY,
First_Name VARCHAR (20),
Address VARCHAR (20),
Age Int NOT NULL,
Percentage Int NOT NULL,
Grade VARCHAR (10)
);
INSERT INTO Student VALUES (201, Akash, Delhi, 18, 89, A2),
(202, Bhavesh, Kanpur, 19, 93, A1),
(203, Yash, Delhi, 20, 89, A2),
(204, Bhavna, Delhi, 19, 78, B1),
(05, Yatin, Lucknow, 20, 75, B1),
(206, Ishika, Ghaziabad, 19, 51, C1),
(207, Vivek, Goa, 20, 62, B2);

SELECT * FROM Student_Records;

b) Restricting and sorting data.


SELECT *|{[DISTINCT] column| expression [alias],..}
FROM table
[WHERE condition(s)]

C)Displaying data from multiple tables.


SELECT tablename1.colunmnname, tablename2.columnname FROM tablename1
Maharishi University of Information Technology
JOIN tablename2

d)Aggregating data using group function


SELECT column1, column2...,
Aggregate(column3, column4,..)
FROM Table_name WHERE Condition...
//OPTION-1 (depending on the condition)
GROUP BY column1,column2,.. HAVING Condition...
//OPTION-2 (depending on the condition)
ORDER BY column1,column2,.. DESC(if required);

e) Manipulating data
UPDATE table
SET column = value [, column = value ...]
[WHERE condition]

DELETE FROM table_name

[WHERE condition];

TRUNCATE [table name]

f) Creating and managing tables.


CREATE TABLE Student_Records
(
Student_Id Int PRIMARY KEY,
First_Name VARCHAR (20),
Address VARCHAR (20),
Age Int NOT NULL,
Percentage Int NOT NULL,
Grade VARCHAR (10)
);
Maharishi University of Information Technology

Experiment No. 4
Objective: Write SQL queries using logical operators (=, <, >, etc.)
Create table emp
(emp_name varchar2(20),
emp_no number(5),
emp_dept varchar2(10),
salary number(10,2));

To insert data into tables:


Insert into emp values
(‘deepak’, 13, ‘cs’, 10000.87);

Insert into emp values


(‘&emp_name’, &emp_no, ‘&emp_dept’, &salary);

To retrieve data from the table:

Select * from emp


Where salary < 5000;

Select * from emp


Where emp_no > 20;

Select * from emp


Where emp_name = ‘Rakesh’;

Select emp_name, salary


Where salary >= 10000;

Experiment No. 5
Objective: Write SQL queries using SQL operators (between..end, IN(List),
Like, IS NULL and also with negating expressions.

Create table emp


(emp_name varchar2(20),
emp_no number(5),
emp_dept varchar2(10),
salary number(10,2));

To insert data into tables:


Insert into emp values
Maharishi University of Information Technology
(‘deepak’, 13, ‘cs’, 10000.87);

Insert into emp values


(‘&emp_name’, &emp_no, ‘&emp_dept’, &salary);

Select * from emp


Where salary between 9000 and 11000;

Select * from emp


Where emp_name IN (‘deepak’, ‘ravi, ‘rakesh’, ‘ranjeet’);

Select * from emp


Where emp_name Like ‘_a%’ or emp_name Like ‘d%’

Select * from emp


Where emp_dept = ‘CS’ and salary < 10000;

Select * from emp


Where not emp_dept = ‘cs’

Experiment No. 6
Objective: Write SQL query using character, number and
date data types.
Create table emp
(EID char(10),
ENAME char(25),
DOJ datetime,
SALARY numeric(9, 2));

Insert the following data:


E1 JYOTI 01/08/2002 25000
E2 IBA 01/08/2003 26000
E3 NITIN 01/09/2003 27000
E4 AMIT 10/09/2003 28000
E5 AJEET 01/08/2004 29000
E6 DEB 01/08/2005 25000
E7 DHARAM 01/08/2006 26000
E8 MUNISH 01/08/2007 27000
E9 ANCHAL 01/08/2008 28000
E10 ANJALI 01/08/2010 29000

Select all employees who joined after 01 January 2005.


Select * from emp
Where DOJ > ‘20050101’;

Select all employees who joined after DEB


Maharishi University of Information Technology
Select S.ENAME, S.DOJ
From emp as S, emp as T
Where T.ENAME = ‘DEB’
And S.DOJ > T.DOJ;

What is the difference period in the joining of DEB and DHARAM


Select DateDiff ( day, T.DOJ, S.DOJ
From emp as S, emp as T
Where T.ENAME = ‘DEB’
And S.ENAME = ‘DHARAM’;
Select names of employees who joined more than 2 years ago
Select ENAME
From EMP
Where DateDiff(month, GetDate(), DOJ) >= 24;
Write SQL query using character, number and date data types.

Create table emp


(EID char(10),
ENAME char(25),
DOJ datetime,
SALARY numeric(9, 2));

Insert the following data:


E1 JYOTI 01/08/2002 25000
E2 IBA 01/08/2003 26000
E3 NITIN 01/09/2003 27000
E4 AMIT 10/09/2003 28000
E5 AJEET 01/08/2004 29000
E6 DEB 01/08/2005 25000
E7 DHARAM 01/08/2006 26000
E8 MUNISH 01/08/2007 27000
E9 ANCHAL 01/08/2008 28000
E10 ANJALI 01/08/2010 29000

Select all employees who joined after 01 January 2005.


Select * from emp
Where DOJ > ‘20050101’;

Select all employees who joined after DEB


Select S.ENAME, S.DOJ
From emp as S, emp as T
Where T.ENAME = ‘DEB’
And S.DOJ > T.DOJ;

What is the difference period in the joining of DEB and DHARAM


Select DateDiff ( day, T.DOJ, S.DOJ
From emp as S, emp as T
Maharishi University of Information Technology
Where T.ENAME = ‘DEB’
And S.ENAME = ‘DHARAM’;
Select names of employees who joined more than 2 years ago
Select ENAME
From EMP
Where DateDiff(month, GetDate(), DOJ) >= 24;

Experiment No. 7
Objective: Write SQL queries using group by and having
clause.

Create account table:

Create table account


(Acc_No Char(5),
BrName Char(20),
Balance Numeric (10, 2));

Insert data into account table:

A1 STROAD 15000
A2 MANDICHOWK 16000
A3 KATGHAR 18000
A4 CIVILLINES 21000
. . .
. . .
. . .
. . .
A20 STROAD 17000

Select BrName, avg(Balance)


From account
Group by BrName;

Select BrName, avg(Balance)


From account
Where BrName IN (‘StRoad’, ‘Katghar’)
Group by BrName;

Select BrName, avg(Balance)


From account
Where BrName IN (‘StRoad’, ‘Katghar’)
Group by BrName
Having avg(Balance) > 15000;
Maharishi University of Information Technology

Experiment No. 8
Objective: Write SQL queries for UNION, INTERSECT and MINUS.

The number of columns and the data types of respective columns being selected must be identical.

Create table cust_mstr


(cust_no varchar2(5),
Name varchar2(20));

Create table addr_dtls


(code_no varchar2(5),
City varchar2(20));

Create table emp_mstr


(emp_no varchar2(5),
Name varchar2(20));

Insert into cust_mstr values


(‘&cust_no’, ‘&name’);

Similarly insert into addr_dtls and emp_mstr.

Select cust_no, name


From cust_mstr, addr_dtls
Where cust_mstr.cust_no = addr_dtls.code_no
And addr_dtls.city = ‘Mumbai’
And addr)_dtls.code_no LIKE ‘c%’
UNION
Select emp_no, name
From emp_mstr, addr_dtls
Where emp_mstr.emp_no = addr_dtls.code_no
And addr_dtls.city = ‘Mumbai’
And addr_dtls.code_no LIKE ‘E%’;

Create table acct_fd_cust_dtls


(Cust_no varchar2(5),
Acct_fd_no varchar2(5));

Insert into acct_fd_cust_dtls values


(‘&cust_no’, &acct_fd_no’);

Select distinctcust_no
From acct_fd_cust_dtls
Where acct_fd_no LIKE ‘CA%’
Or acct_fd_no LIKE ‘SB%’
Maharishi University of Information Technology
INTERSECT
Select distinct cust_no
From acct_fd_cust_dtls
Where acct_fd_no LIKE ‘FS%’;

Replace INTERSECT with MINUS.

Experiment No. 9
Objective: Write SQL queries for extracting data from more than one table (EQUI JOIN, NON
EQUI JOIN, Outer Join).

Create table emp_mstr


(emp_no number(5),
Emp_name varchar2(20),
Dept varchar2(10),
Design varchar2(10),
Branch_no number(5));

Insert into emp_mstr values


(&emp_no, ‘&emp_name’, ‘&dept’, ‘&desig’, &branch_no);

Create table branch_mstr


(name varchar2(20),
Branch_no number(5));

Insert into branch_mstr values


(‘&name’, &branch_no);

Select E.emp_no, E.emp_name, B.name, E.dept, E.desig


From emp_mstr E INNER JOIN branch_mstr B
ON B.branch_no = E.branch_no;

Select E.emp_no, E.emp_name, B.name, E.dept, E.desig


From emp_mstr E, branch_mstr B
Where B.branch_no = E.branch_no;

Create table cntc_dtls


(code_no number(5),
Cntc_type varchar2(5),
Cntc_data varchar2(20));

Insert into cntc_dtls values


(&code_no, ‘&cntc_type’, ‘&cntc_data’)

Select E.emp_name, E.dept, C.cntc_type, C.cntc_data


From emp_mstr e LEFT JOIN cntc_dtls C
ON E.emp_no = C.code_no;
Maharishi University of Information Technology

Experiment No. 10
Objective: Write SQL queries for sub queries, nested
queries.
Find out all customers having same names as the employees.

Create table cust_mstr


(Fname varchar2(15),
Lname varchar2(15));

Insert into cust_mstr values


(‘&fname’, ‘&lname’);

Create table emp_mstr


(Fname varchar2(15),
Lname varchar2(15));

Insert into emp_mstr values


(‘&fname’, ‘&lname’);

Select fname, lname


From cust_mstr
Where (fname, lname) IN
(select fname, lname from emp_mstr);

List accounts alongwith the current balance, the branch to which it belongs and the average balance of
the branch, having a balance more than the average balance of the branch, to which the count belongs.

Create table acct_mstr


(acct_no varchar2(5),
Curbal number(12,2),
Branch_no varchar2(5));

Insert into acct_mstr values


(‘&acct_no’, &curbal, ‘&branch_no’)

Select A.acct_no, A.curbal, A.branch_no, B.avgbal


From acct_mstr A, (Select branch_no, avg(curbal) avgbal from acct_mstr
Group by branch_no) B
Where A.branch_no = B.branch_no
And A.curval > B.avgbal
Maharishi University of Information Technology

You might also like