Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 26

TRIBHUVAN UNIVERSITY

SWOYAMBHU INTERNATIONAL COLLEGE


LAGANKHEL, LALITPUR
NEPAL

LAB REPORT
OF
Database Management System

Submitted By: Submitted To:


Name: Kamlesh Kumar Mahato Er. Suresh Kr. Mahato
Database Management System
Roll no.: 10
(Swoyambhu International
BBM 6th Semester College)
Bachelor of Business Management
CERTIFICATE

This is to certificate that the Practical Work entitled “Database


Management System” is a Bonafide work carried out by
‘‘Kamlesh Kumar Mahato’’ in partial fulfillment of 6th semester
of Bachelor in Business Management of Tribhuvan University,
during the Year 2023-2024. The practical report has been
approved as it satisfies the academic requirements.

GUIDE HOD
Er. Suresh Kr. Mahato Mr. Rajkumar Shah
Asst. Professor (Department of BBM)

------------------------- -------------------------
Signature with Date Signature with Date

1
Tribhuvan University
Faculty of Management
Swoyambhu International College

LETTER OF APPROVAL

This lab report bind with the entitle “Database Management System -Lab Report”
prepared
By
Kamlesh Kumar Mahato
Batch of 2020 of Swoyambhu Int’l College, Lagankhel, Lalitpur
Registration No: 7-2-927-708-2020
As a partial fulfillment for requirement for the degree of Bachelor in Business
Management has been evaluated, in our view, this project includes all the quality
elements for the required degree.

…………………………… ……………………………….
Er. Suresh Kumar Mahato External Examiner
Internal Examiner

2
ACKNOWLEDGMENT

To make any lab report, essential guidance and references is mostly required
without which proper report cannot be prepared. So, I would like to express
my gratitude towards Mr. Suresh Kr. Mahato, who enable me to complete
this lab report successfully in all the aspects. I am also very thankful to Mr.
Rajkumar Sah, BBM coordinator for his encouragement and importance
guidance regarding this project. Similarly, I would like to express thank to all
the teaching and non-teaching staff of Swoyambhu Int’l College for
providing importance resources to complete this report.

Lastly, I am very grateful to Tribhuvan University (FOMECD), Dean Office


for providing this opportunity and addressing this lab report in BBM
curriculum so that it will help in building great career through the practical
knowledge.

Kamlesh Kumar Mahato


(Batch of 2020)

3
PREFACE

This lab report entitled as “Database Management System -Lab


Report” is prepared and designed as per the direction to fulfill the
requirement for the BBM degree conducted by Tribhuvan University.

This report covers all the lab requirement prescribed by TU and each
practical topics are included in this project; this lab report may help
upcoming batch students as a sources of references. I have tried to
minimize all the errors presents here as far as possible. Although, every
effort has been made to make this lab report as clear and accurate,
however suggestion for the improvement needed for the further report
are most welcome and will be highly appreciated.

4
Table of Contents
THEORY OF SQL..............................................................................................................................5
1.1 . Introduction to SQL.........................................................................................................5
1.2 SQL Commands......................................................................................................................6
1.3 SQL Integrity Constraints.....................................................................................................6
1.5 Types of Join in SQL............................................................................................................10
DATA QUERY LANGUAGE...........................................................................................................12
2.1 Different ways of select statement.......................................................................................13
2.2 SQL statement using ‘where’ clause....................................................................................14
2.3 SQL statement using different operator.............................................................................14
2.4 SQL statement using wildcard operators............................................................................15
2.5 SQL statement using regular expression.............................................................................15
Assignment.........................................................................................................................................17
1. Entity-Relationship Diagram....................................................................................................18
2. Queries:.....................................................................................................................................18
Tables Creation:............................................................................................................................18
Description:....................................................................................................................................19
Insertion Value:.............................................................................................................................20
Selection Values:............................................................................................................................22
Queries’s Solution:........................................................................................................................23
Conclusion...........................................................................................................................................24
References..........................................................................................................................................25

THEORY OF SQL
1.1. Introduction to SQL

5
SQL stands for “Structured Query Language” and is term as a query language used for
accessing and modifying information in the database, SQL was first developed in 1970s by
IBM and also an ANSI/ISO standard. It has become a Standard Universal Language used by
most of the relational database management system (RDBMS).

1.2 SQL Commands


SQL commands are instructions used to communicate with the database to perform
specific task that work with data. SQL commands can be used not only for searching the
database but also to perform various other functions like creating table, add on data to
tables or modify data, drop the table and many more. SQL commands are grouped into
four major categories depending on their functionality:

 Data Definition Language(DDL):


These SQL commands are used for creating, modifying, and dropping the structure of
database objects. The commands are CREATE, ALTER, DROP, RENAME and
TRUNCATE.

 Data Manipulation Language (DML):


These SQL commands are used for storing, retrieving, modifying and deleting data.
These commands are SELECT, INSERT, UPDATE and DELETE.

 Transaction Control Language (TCL):


These SQL commands are used for managing changes affecting the data. These
commands are COMMIT, ROLLBACK.

 Data Control Language (DCL):


These SQL commands are used for providing security to database objects. These
commands are GRANT and REVOKE.

1.3 SQL Integrity Constraints

6
Integrity Constraints are used to apply business rules for the database tables. The constraints
available in SQL are Primary Key, Foreign Key, Not Null, Unique and Check. Constraints
can be defined in two ways:
 The constraints can be specified immediately after the column definition. This is
called column-level definition.

 The constraints can be specified after all the columns are defined. This is called table-
level definition.

1) Primary Key:
This constraint defines a column or combination of columns which uniquely identifies
each row in the table.

Syntax:
Column Name datatype [constraint constraint name] PRIMARY KEY

Queries:
Mysql > create table practical (
o Id int Primary key,
o Assignment name varchar (50)
o );
Query OK, 0 rows affected (0.08 sec)
2) Foreign Key:
This constraint identifies any column referring the PRIMARY KEY in another table.
It establishes a relationship between two columns in the same table or between
different tables. For a column to be defined as a foreign key, it should be a defined as
a primary key in the table which it is referring. One or more columns can be defined
as foreign key.
Syntax:
[Constraint constraint name] References
Queries:
Mysql > create table table ones(
o Id int
o Name varchar (20),,
o Foreign key(id) reference practical(id)
o );
o Query ok,0 rows affected(0.04sec)
3) Not Null Constraint:
This constraint ensures all rows in the table contains a definite value for the column
which is specified as not null which means null value is not allowed.

Syntax:
[Constraint constraint name] Not Null

7
Queries:
Mysql > create table practical one(
o id int not null,
o name varchar(30)
o );
Query OK, 0 rows affected (0.08 sec)

2) Unique Key:
This constraint ensures that a column or a group of columns in each row have a
distinct value. A columns can have a null value but the values cannot be repeated.

Syntax:
[Constraint constraint_name] Unique
Queries:
Mysql > create table practical_two(
o Id int ,
o name varchar(10) unique
o );
Query OK, 0 rows affected (0.08 sec)
Query OK, 0 rows affected (0.08 sec)

Insert Statement:
The INSERT INTO statement is used to insert a new row in a table.

Syntax:
INSERT INTO table_name Values (value1, value2, …….);
Queries:
Mysql > Insert into queries(‘id’,’name’)
o Values (‘1’,’sanjana’),
o (‘2’,’Shrijana’);
Query OK, 0 rows affected (0.00sec)
Select Statement:
The SELECT statement is used to select data from a database. The result is stored in a
result table, called as the result-set.

Syntax:
SELECT * from table_name;

8
Queries:
Myssql>select * from queries;
Id name
1 Sanjana
2 Shrijana

Query 2 rows in set in(0.00 sec)

Update Statement:
The UPDATE statement is used to update existing records in the table.
Syntax:
UPDATE table_name SET column=value where some_column=some_value;
Queries:
Mysql > update queries set name=”sanj where=’1’;
Query OK, 0 rows affected (0.08 sec)
Rows matched:1 Changed: 1 warnings:0

Delete Statement:
The DELETE statement is used to delete rows in a table.

Syntax:
DELETE from table_name where some_column=some_value;
Queries:
Mysql> Delete from queries where id=”1”;
Query ok,1 row affected(0.00sec)
Alter Statement:

The SQL ALTER table commands is used to modify the definition structure of the table.
Syntax:
ALTER table table_name ADD column_name datatype;
Queries:
Mysql>Alter table queries add address varchar(50);
Query OK,1 row affected(1.16 sec)

9
Records:1Duplicates:0 warnings:0
Mysql>select*from queries;
Id Name Address

2 Shrijana NULL

1 row in set (0.00 sec)

Truncate Table:
The SQL Turncate table is used when we want to delete the data inside the table but not
the table itself.
Syntax:
TRUNCATE table table_name;
Queries:
Mysql > Truncate table queries;
Query OK, 0 rows affected (0.00 sec)
Mysql > select* from queries;
Empty set (0.00 sec
Drop Table
The DROP table statement is used to delete an entire table.
Syntax:
DROP table table_name;
Queries:
Mysql > Drop table queries;
Query OK, 0 rows affected (0.96 sec)

1.5 Types of Join in SQL

Inner Join:
This type of join returns records that have matching values in both tables.
Syntax:
SELECT column1, column2, …..
10
From table_name1
Inner Join table_name2
On table_name1.field=table_name2.field;

Queries:
Mysql > select id,name,amount,date
o From customers
o Inner join orders
o On customers.id=orders.cus_id;
4 rows in set (0.11 sec)
Id Name Amount Date

11 Sanjana 3000 000-00-00

22 Shrijana 1500 000-00-00

22 Sujata 1000 000-00-00

33 Sita 1400 000-00-00

Left Join:
This types of join returns all records from the left table, and the matched records from
the right table

Syntax:
SELECT column1, column2, …..
From table_name1
Left Join table_name2
On table_name1.field=table_name2.field;

Mysql > select id, name,amount, salary


o From customers

11
o left join orders
o On customers.id=orders.cus_id;

Id name amount Salary


11 Sanjana 3000 15000
22 Shrijana 1500 20000
22 Sujata 1000 12000
33 Sita 1400 10000

Right Join:
This types of join returns all records from the right table, and the matched records from
the left table

Syntax:
SELECT column1, column2, …..
From table_name1
Right Join table_name2
On table_name1.field=table_name2.field;

Id Name address Salary


11 Sanjana Butwal 15000
22 Shrijana Pokhara 20000
22 Sujata Chitwan 12000
33 Sita syangja 10000

DATA QUERY LANGUAGE

DQL commands are basically SELECT statement. SELECT statements let you query the
database to find information in one or more tables, and return the query as a result set. It is
used to fetch the information from the database which is already store there.

12
Syntax:
SELECT [ALL|DISTINCT] fieldname
FROM table_name
[where condition];

2.1 Different ways of select statement

Selecting data from a single column:


Query:
Mysql>select dept_name from department;
Department
BCA
BSC CSIT
BIM
3 rows in set (0.00 sec)

Selecting data from multiple column

Query:
Mysql>select dept_id, dept_block,dept_dean from department;
Dept_id Dept_block Dept_dean
1 20 Sanjana

2 40 Sujata

3 5 Baburam

Selecting data from all column of a table

Query:
Mysql>select dept_name from department;
Dept_id Dept_name Dept_block Dept_dean
1 BCA 20 Sanjana
2 MCA 40 Shrijana
3 BIT 5 Sujata

13
2.2 SQL statement using ‘where’ clause

Queries:
Mysql>select * from departm where dept_dept=’Shrijana’
Dept_id Dept_name Dept_block Dept_dean
2 MCA 40 Shrijana
1 row in set(0.00 sec)

Query data from table using ‘Distinct’ statement

Queries:

Mysql>select * destinct(dept_name) from department;


Dept_name
BCA
MCA
BIT

2.3 SQL statement using different operator

Queries:

Mysql>select * from departent where dept_id =’1’ and dept_block=’20’


Dept_id Dept_name Dept_block Dept_dean
1 BCA 20 Sanjana

Mysql>select * from departm where dept_id=’1’ or dept_block=’5’;


Dept_id Dept_name Dept_block Dept_dean
1 BCA 20 Sanjana
2 BIT 5 Sujata

2.4 SQL statement using wildcard operators

Queries:

Mysql>select * from departm where dept_dept=’Sujata’


Dept_id Dept_name Dept_block Dept_dean
3 BIT 5 Sujata

14
Mysql>select * from department where dept_dean like’u%’;
Dept_id Dept_name Dept_block Dept_dean
3 BIT 5 Sujata

Mysql>select * from department where dept_name like “%t”


Dept_id Dept_name Dept_block Dept_dean
3 BIT 5 Sujata

Mysql>select * from departm where dept_dean like ’%jana’;
Dept_id Dept_name Dept_block Dept_dean
1 BCA 20 Sanjana
3 MCA 40 Shrijana

Mysql>select * from departm where dept_dean like ’%Su’;


Dept_id Dept_name Dept_block Dept_dean
2 BIT 5 Sujata

Mysql>select * from department where dept_block like ‘_’;


Dept_id Dept_name Dept_block Dept_dean
1 BCA 20 Sanjana
2 BIT 5 Sujata

2.5 SQL statement using regular expression

Queries:
Mysql>select * from department where dept_block like ‘_’;
Dept_id Dept_name Dept_block Dept_dean
1 BCA 20 Sanjana
2 MCA 40 Shrijana

Mysql>select * from department where dept_name like “%r”


Dept_id Dept_name Dept_block Dept_dean

15
1 MCA 40 Shrijana

Mysql>select * from department where dept_name like “%n”


Dept_id Dept_name Dept_block Dept_dean
1 BCA 20 Sanjana
2 MCA 40 Shrijana

16
Assignment
Q.No.1. Consider the schema for Movie Database:
ACTOR (Act_id, Act_Name, Act_Gender)
DIRECTOR (Dir_id, Dir_Name, Dir_Phone)
MOVIES (Mov_id, Mov_Title, Mov_Year, Mov_Lang, Dir_id)
MOVIE_CAST (Act_id, Mov_id, Role)
RATING (Mov_id, Rev_Stars)
Write SQL queries to
1. List the titles of all movies directed by ‘Santosh Sen’.
2. Find the movie names where one or more actors acted in two or more movies.
3. List all actors who acted in a movie before 2000 and also in a movie after 2015 (use JOIN
operation).
4. Find the title of movies and number of stars for each movie that has at least one rating
and find the highest number of stars that movie received. Sort the result by movie title.
5. Update rating of all movies directed by ‘Bhuwan K C’ to 5.

17
1. Entity-Relationship Diagram
Solution,

Act_id Dir_Id Dir_Name


Act_Name

Actor Dir_phone
Act_Gender Director

Has
Movie_
Cast
Role
Rev_Sta
r
Movies
Mov_Lang
Mov_id

Mov_Title Mov_Year

Fig: Entity-Relationship Diagram Movie Database

2. Queries:
Tables Creation:

18
Description:
Description of tables:

Insert Values:

Insert Values:

19
Insertion Value:

20
21
Selection Values:

22
Queries’s Solution:

1. List the titles of all movies directed by ‘Santosh Sen’.


Solution,

2. Find the movie names where one or more actors acted in two or more movies.
Solution,

3. List all actors who acted in a movie before 2010 and also in a movie after 2015 (use
JOIN operation).
Solution,

4. Find the title of movies and number of stars for each movie that has at least one
rating and find the highest number of stars that movie received. Sort the result by
movie title.
Solution,

5. Update rating of all movies directed by ‘Bhuwan K C’ to 5.


Solution,

23
Conclusion

In summary, the SQL queries we used offer a detailed look into the Movie Database
setup, helping us understand its structure and contents better. These queries show
how SQL can efficiently handle different tasks like finding specific movie titles or
analyzing relationships between actors and movies.

For instance, our first query simply found all movies directed by 'Santosh Sen',
demonstrating how SQL can quickly fetch specific information. The second query
went a step further, identifying movies where actors appeared in multiple films,
showcasing SQL's ability to handle more complex tasks.

In our third query, we connected different tables to find actors who acted in movies
before 2000 and after 2015, showing how SQL can bring together different pieces of
data for analysis. The fourth query used SQL's functions to calculate movie ratings
and find the highest-rated film, giving insights into viewer preferences.

Finally, our fifth query demonstrated SQL's ability to update data, like changing movie
ratings. Alongside these queries, the Entity-Relationship Diagram visually represents
the database's structure, making it easier to understand.

In conclusion, these SQL queries and the ER Diagram underline the importance of
structured query languages in working with databases. SQL's flexibility and efficiency
make it essential for tasks like data analysis and management. With SQL, users can
effectively explore databases, uncover insights, and make informed decisions based
on the information at hand.

24
References
 Er.Shankar N.Adhikary; Database Management System. Advance Saraswati
Prakashan Pvt. Ltd., 1 st Edition (2022 March)
 Bhupendra Singh Saud & Indra Chaudhary; Database Management System.
KEC Publication & Distribution Pvt. Ltd., 1 st Edition (2022).
 Wikipedia. (2024, March 22). Database Management System. Retrieved from
https://en.wikipedia.org/wiki/Database_management_system.

25

You might also like