0% found this document useful (0 votes)
14 views

DBMS Lab Manual Exp I & Exp II

The document is a lab manual for the Database Management System course at the Global Institute of Technology, detailing course outcomes, syllabus, objectives, and experiments for students. It covers essential concepts of databases, including the structure and use of SQL, as well as practical exercises for designing and manipulating databases. The manual emphasizes the importance of understanding relational database concepts and provides guidelines for completing lab exercises effectively.

Uploaded by

fopivac546
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)
14 views

DBMS Lab Manual Exp I & Exp II

The document is a lab manual for the Database Management System course at the Global Institute of Technology, detailing course outcomes, syllabus, objectives, and experiments for students. It covers essential concepts of databases, including the structure and use of SQL, as well as practical exercises for designing and manipulating databases. The manual emphasizes the importance of understanding relational database concepts and provides guidelines for completing lab exercises effectively.

Uploaded by

fopivac546
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/ 15

Global Institute of Technology

Department of Computer Science & Engineering

LAB MANUAL FOR

DATABASE MANAGEMENT SYSTEM LAB

II YEAR B. TECH. IV SEM

CS/IT/AI&DS BRANCH

SUBJECT CODE: 4CS4-22

Department of CSE/IT/AI & DS

Prepared By: Dr. Sangeeta Soni


Assistant Professor

1
Global Institute of Technology
Department of Computer Science & Engineering

1. COURSE OUTCOMES
CO-1: Demonstrate the basic elements of a relational database management system.
CO-2: Design entity relationship and convert entity relationship diagrams into RDBMS and formulate
SQL queries on the respect data into RDBMS and formulate SQL queries on the data.
CO-3: Design a commercial relational database system (Oracle, MySQL) by writing SQL using the
system.
CO-4: Analyze and select storage and recovery techniques of database system.

2. SYLLABUS
4CS4-22: Database Management System Lab
Credit: 1.5, Max. Marks: 100 (IA:60, ETE:40)
0L+0T+3P

List of Experiments:
1. Design a Database and create required tables. For e.g. Bank, College Database.
2. Apply the constraints like Primary Key, Foreign key, NOT NULL to the
tables.
3. Write a SQL statement for implementing ALTER,UPDATE and DELETE.
4. Write the queries to implement the joins.
5. Write the query for implementing the following functions: MAX (), MIN (), AVG () and
COUNT ().
6. Write the query to implement the concept of Integrity constrains.
7. Write the query to create the views.
8. Perform the queries for triggers.
9. Perform the following operation for demonstrating the insertion, updation and
deletion. 10.Using the referential integrity constraints.
11.Write the query for creating the users and their role.

3. OBJECTIVES: At the end of the course, the students will be able to:

1. Understand the basic concepts and the applications of database systems.


2. Preparing E-R diagram & Finding the data fields to be used in the database.
3. Understand the Relational database design principles.
4. Finding the data fields to be used in the database & Selecting fields for keys.

2
Global Institute of Technology
Department of Computer Science & Engineering

5. Normalizing the database including analysis of functional dependencies.


6. Master the basics of SQL and construct queries using SQL.
7. Familiar with the basic issues of transaction processing and concurrency control.
8. Familiar with database storage structures and access technique.

In order to achieve the above objectives, it is expected that each student will chose one
problem. The implementation shall being with the statement of the objectives to be
achieved, preparing ER diagram, designing of database, normalization and finally
manipulation of the database including generation of reports, views etc. The problem may
first be implemented for a standalone system to be used by a single user.
All the above steps may then be followed for development of a database application to be
used by multiple users in a client server environment with access control. The application
shall NOT use web techniques.
One exercise may be assigned on creation of table, manipulation of data and report
generation using SQL.
The aim of this course is to provide an introduction to Database management system,
with an emphasis on foundational material the fundamental concepts and algorithms
covered are based on those used in existing commercial or experimental database
systems.

Upon successful completion of this Lab the student will be able to:

 Creating & Modifying database objects

 Manipulating the data

 Retrieving the data from the database server

 Performing database operations (create, update, modify, retrieve, etc.,) using front-

end tools.

 Design and develop applications like banking, reservation system, etc.

3
Global Institute of Technology
Department of Computer Science & Engineering

4. INTRODUCTION TO DATABASE MANAGEMENT SYSTEM

DATABASE
‘DATA’ is originated from the word ‘datum’ that means ‘single piece of information’. It
is plural of the word datum. A database is an organized collection of i n t e r - related
data, generally stored and accessed electronically from a computer system.

Database Management System (DBMS)

A Database Management System (DBMS) is software application that enables users to


create, access and manage a database by modifying them. The DBMS is hence a general-
purpose software system that facilitates the processes of defining, constructing,
manipulating, and sharing databases among various users and applications.

Applications of DBMS
Databases are widely used. Some applications of database systems are given below:

1. Banking: For customer information, accounts, and loans, and banking


transactions.
2. Airlines: For reservations and schedule information.
3. Universities: For student information, course registrations, and grades.
4. Credit card transactions: For purchases on credit cards and generation of
monthly statements.
5. Telecommunication: For keeping records of calls made, generating monthly
bills, maintaining balances on prepaid calling cards, and storing information about
the communication networks.
6. Finance: For storing information about holdings, sales, and purchases of financial
instruments such as stocks and bonds.
7. Sales: For customer, product, and purchase information.
8. Manufacturing: For management of supply chain and for tracking production of
items in factories, inventories of items in warehouses/stores, and orders for items.

4
Global Institute of Technology
Department of Computer Science & Engineering

9. Human resources: For information about employees, salaries, payroll taxes and
benefits, and for generation of paychecks.

Advantages of DBMS
Using a DBMS to manage data has following advantages:
1. Data independence: Application programs should be as independent as possible

from details of data representation and storage. The DBMS can provide an
abstract view of the data to insulate application code from such details.
2. Efficient data access: A DBMS utilizes a variety of sophisticated techniques to

store and retrieve data efficiently. This feature is especially important if the data is
stored on external storage devices.
3. Data integrity and security: If data is always accessed through the DBMS, the

DBMS can enforce integrity constraints on the data. For example, before inserting
salary information for an employee, the DBMS can check that the department
budget is not exceeded. Also, the DBMS can enforce access controls that govern
what data is visible to different classes of users.

4. Data administration: When several users share the data, centralizing the

administration of data can offer significant improvements. Experienced


professionals, who understand the nature of the data being managed, and how
different groups of users use it, can be responsible for organizing the data
representation to minimize redundancy and for fine-tuning the storage of the data
to make retrieval efficient.
5. Concurrent access and crash recovery: A DBMS schedules concurrent accesses

to the data in such a manner that users can think of the data as being accessed by
only one user at a time. Further, the DBMS protects users from the effects of
system failures.
6. Reduced application development time: Clearly, the DBMS supports many

important functions that are common to many applications accessing data stored
in the DBMS. This, in conjunction with the high-level interface to the data,

5
Global Institute of Technology
Department of Computer Science & Engineering

facilitates quick development of applications. Such applications are also likely to


be more robust than applications developed from scratch because many important
tasks are handled by the DBMS instead of being implemented by the application.

People dealing with databases


Below are categories of people who deal with databases:
1. Database Implementers: People in this category are associated with the creation
and use of databases. These people build DBMS software. Database implementers
work for vendors such as IBM or Oracle.
2. End Users: End users store and use data in a DBMS. End users come from a
diverse and increasing number of fields. Many end users simply use applications
written by database application programmers, and so require little technical
knowledge about DBMS software. However, sophisticated users who make more
extensive use of a DBMS, such as writing their own queries, require a deeper
understanding of its features.

3. Database application programmers: These people develop packages that


facilitate data access for end users using the host or data languages and software
tools that DBMS vendors provide (Such tools include report writers,
spreadsheets, etc.).
4. Database administrator (DBA): The DBA is responsible for authorizing access
to the database, for coordinating and monitoring its use, and for acquiring
software and hardware resources as needed. The DBA is accountable for
problems such as breach of security or poor system response time.

5. ENTITY-RELATIONSHIP MODEL (E-R Model)

A database can be modeled as:


 A collection of entities,
 Relationships among entities.

6
Global Institute of Technology
Department of Computer Science & Engineering

Entity: A real-world object that can be distinctly identified may represent some real
physical object E.g. Student; Car. May represent some conceptual idea E.g., SC304 is a
course; Semester 1 2001/2002 is a semester. An entity is an object that exists and is
distinguishable from other objects.

Entity set: An entity set is a set of entities of the same type that share the same
properties. Example: set of all persons, companies, trees, holidays.

An Entity should be:


• An Object that will have many instances in the Database
• An Object that will have multiple attributes
• An Object that we are trying to model

An Entity should not be:


• User of the Database
• An output of the Database (eg. Report)

Attributes: An entity is represented by a set of attributes, that is, descriptive properties


possessed by all members of an entity set (value from corresponding entity).
Example: customer = (customer-name, social-security, customer-street, customer-city)
account = (account-number, balance)

Domain: Domain is the set of permitted values for each attribute.

Attribute types:
• Simple and composite attributes.
• Single-valued and multi-valued attributes
• Null attributes
• Derived attributes
• Identifiers (Key) attributes

7
Global Institute of Technology
Department of Computer Science & Engineering

6. INTRODUCTION TO SQL

SQL stands for Structured Query Language. SQL is standard language for interacting
with a relational database.
A table is primary database object of SQL, which is used to store the data in the form of
rows and columns. SQL developed by IBM is used as standard language to access data
from database. In order to communicate with database SQL has been divided into four
sub languages and each sub language consists of different commands, they are:

1. Data Definition Language (DDL): DDL commands are used to define the database
structure or schema.
Different DDL commands are:
CREATE - To create database or its objects
ALTER – To alter the structure of the database
DROP – To delete objects from the database
TRUNCATE – To remove all records from a table, including all spaces allocated for
the records are removed
RENAME – To rename an object existing in the database.

2. Data Manipulation Language (DML): DML commands are used for manipulation
of data present in the database.
Different DML commands are:
INSERT – To insert data into a table
UPDATE – To updates existing data within a table
DELETE – To deletes records from a table

3. Data Control Language (DCL): DCL commands are used to control the access to
the database objects.
Different DCL commands are:
GRANT – To gives user's access privileges to database
REVOKE – To withdraw user’s access privileges given with the GRANT command

8
Global Institute of Technology
Department of Computer Science & Engineering

4. Transaction Control Language (TCL): TCL commands are used to manage the
changes made by DML statements. It allows statements to be grouped together into
logical transactions.
Different TCL commands are:
COMMIT – To save work done
SAVEPOINT – To identify a point in a transaction to which you can later roll back
ROLLBACK – To restore database to original since the last COMMIT

Experiment - 1
AIM: Design a Database and create required tables. For e.g. Bank, College Database

Creation of Database: Syntax: CREATE DATABASE databasename;

How to use the database you have created: USE databasename;

How to create a table:


CREATE TABLE table_name(column1 datatype, column2 datatype, column3 datatype)

Creating table college:

create table college (stu_id int(10), stu_name varchar(30), stu_dept varchar(20),


phonenumber int(10), DOB date, address varchar(50), fathers_name varchar(25),
mothers_name varchar(25));

DESC Command: desc or describe command shows the structure of table which include
name of column, data type of column and the null ability which means, that column can
contain null values or not.

Syntax: DESCRIBE tablename; OR DESC tablename;

9
Global Institute of Technology
Department of Computer Science & Engineering

DDL COMMANDS

1. Creating Database Objects (Create Command)


a) Creating table (without constraints)

Syntax:
Create table <table name>(<col1><data type>(<size>),<col2><datatype>(<size>));
Ex:
Create table emp(empnonumber varchar(4), ename varchar(10), address varchar(30),
city varchar(10));

b) Creating view

Syntax:

Create view<view name>As (SELECT query);


Ex:
Create view empview As (select empno, city from emp);

2. Modifying the structure of tables (Alter Command)


a) Add new columns
Syntax:
Alter table<table name>add(<new col><data type(size),<new col>data
type(size));
Ex:
Alter table emp add email varchar (50);

b) Modifying existing columns


Syntax:
Alter table<table name>modify(<col><new data type(size));
Ex:
Alter table emp modify(ename varchar(20));

10
Global Institute of Technology
Department of Computer Science & Engineering

c) Renaming existing columns


Syntax:
Alter table<table name> RENAME column <col> to <newcol>;
Ex:
Alter table emp rename column ename to empname;

d) Removing existing columns


Syntax:
Alter table<table name> drop column <col>;
Ex:
Alter table emp drop column salary;

3. Renaming the tables


Syntax:
Rename<old table> to <new table>;
Ex:
Rename emp to emp1;

4. Truncating the tables


Syntax:
Truncate table<table name>;
Ex:
Truncate table emp1;

5. Destroying tables
Syntax:
Drop table<table name>;
Ex:
Drop table emp1;

11
Global Institute of Technology
Department of Computer Science & Engineering

 VIVA QUESTIONS

1. What is database?
A database is a permanent collection of data that is organized. So that it can easily be
accessed, managed, and updated.

2. What is DBMS?
A database management system (DBMS) is an application software that enable users to
create, read, update and delete data in a database. It lets end users to use data while
managing data integrity. It stores data that can be shared by multiple users in a controlled
manner concurrently.

3. What is RDBMS?.
A relational database management system (RDBMS) is based on the relational model. This
model uses relationship between tables using primary keys, foreign keys and indexes.
RDBMS uses constraints of primary and foreign keys to establish relationships between
rows of data in different database tables. It uses the concept of normalization to eliminate the
need to redundantly store related data in multiple tables.

4. Define DDL and DML.


Creating and modifying database objects such as tables is called Data Definition Language
(DDL). Manipulating data in a database such as inserting, updating, deleting is defined as Data
Manipulation Language (DML).

5. What is SQL?
SQL stands for Structured Query Language, is a language to communicate with the
Database. It performs tasks such as retrieval, updation, insertion and deletion of data from a
database.

6. What is Data Model & E-R Model?


Data Model is A collection of conceptual tools for describing data, data
relationships data semantics and constraints. This E-R model is based on real world
that consists of basic objects called entities and of relationship among these objects.
Entities are described in a database by a set of attributes.

7. What are the advantages of DBMS?


I. Redundancy is controlled.
II. Providing multiple user interfaces.
III. Providing backup and recovery
IV. Unauthorized access is restricted.
V. Enforcing integrity constraints.

12
Global Institute of Technology
Department of Computer Science & Engineering

Experiment - 2
AIM: Apply the constraints like Primary Key, Foreign key, NOT NULL to the tables.

Constraints are rules for a database that limit the acceptable data values for a table.
SQL constraints are used to specify rules for data in a table. These are used to limit
the type of data that can go into a table. This ensures the accuracy and reliability of
the data in the database. Constraints could be either on a column level or a table
level. The column level constraints are applied only to one column, whereas the table
level constraints are applied to the whole table.

Constraints can be divided into the following two types :

1. Column level constraints: Limits only column data.


2. Table level constraints: Limits whole table data.

Following are the most used constraints that can be applied to a table.

• NOT NULL
• UNIQUE
• PRIMARY KEY
• FOREIGN KEY
• CHECK

NOT NULL: NOT NULL constraint restricts a column from having a NULL value.
Once NOT NULL constraint is applied to a column, you cannot pass a null value to that
column. It enforces a column to contain a proper value.

CREATE TABLE Student(stu_id int NOT NULL, Name varchar(60), Age int);

UNIQUE : UNIQUE constraint ensures that a field or column will only have unique values. A
UNIQUE constraint field will not have duplicate data. This constraint can be applied at
column level or table level.

13
Global Institute of Technology
Department of Computer Science & Engineering

ALTER TABLE Student ADD UNIQUE(stu_id);

PRIMARY KEY : Uniquely identifies each row/record in a database table. A combination of


a NOT NULL and UNIQUE. this constraint is used to specify a field in a table as primary key.

CREATE TABLE Student (ID int(6) NOT NULL UNIQUE, NAME varchar(10), ADDRESS
varchar(20), PRIMARY KEY(ID));

Applying Primary key constraint Column wise :

ALTER table Student ADD PRIMARY KEY(s_id);

FOREIGN KEY : FOREIGN KEY is used to relate two tables. FOREIGN KEY constraint is
also used to restrict actions and is used to link two tables together. Foreign Key is a field in a
table which uniquely identifies each row of a another table.

CREATE table bank (bank_id int PRIMARY KEY, em_name varchar(60) NOT NULL, stud_id
int FOREIGN KEY REFERENCES college(coll_id));

Applying Foreign key constraint column wise :

ALTER table bank ADD FOREIGN KEY(coll_ id) REFERENCES college(coll_ id);

CHECK : CHECK constraint is used to restrict the value of a column between a range. It
performs check on the values, before storing them into the database. It’s like condition
checking before saving data into a column.

CREATE table Student(stu_ id int NOT NULL CHECK(stu_ id > 0), Name varchar(60)
NOT NULL, Age int);

Applying Check constraint column wise :

ALTER table Student ADD CHECK(stu id > 0);

14
Global Institute of Technology
Department of Computer Science & Engineering

 VIVA QUESTIONS
1. What is a primary key?
A primary key is a unique identifier that uniquely identify a record in a database table. It
has implicit NOT NULL constraint (means primary key values can't be NULL).

2. What is a unique key?


A Unique key ensures rows are unique within the database. It provides uniqueness of the
column on which it is defined.

3. What is foreign key?


A foreign key is a column or group of columns that establishes a link between the data in
two tables. A foreign key ensures referential integrity of the data.

4. Difference between a Primary Key and a Unique Key.


A primary key job is to uniquely identify a row within a table while a Unique key
ensures additional unique conditions on column(s). A primary key enforces entity
integrity whereas Unique key enforces unique data. There may be many unique key
constraints for one table, but only one PRIMARY KEY constraint for one table.

5. What do you understand by Default constraints?


A default constraint enters a value in a column when one is not specified in the Insert or
Update statement.

6. What is a constraint, and why use constraints?


A set of conditions defining the type of data that can be input into each column of
a table. Constraints ensure data integrity in a table and block undesired actions.

7. What is NOT NULL constraints?

This constraint ensures that a column can not have a NULL value. There can be
multiple NOT NULL constraint in any table.

15

You might also like