DBMS Lab Manual Exp I & Exp II
DBMS Lab Manual Exp I & Exp II
CS/IT/AI&DS BRANCH
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:
2
Global Institute of Technology
Department of Computer Science & Engineering
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:
Performing database operations (create, update, modify, retrieve, etc.,) using front-
end tools.
3
Global Institute of Technology
Department of Computer Science & Engineering
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.
Applications of DBMS
Databases are widely used. Some applications of database systems are given below:
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
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
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.
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
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.
9
Global Institute of Technology
Department of Computer Science & Engineering
DDL COMMANDS
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:
10
Global Institute of Technology
Department of Computer Science & Engineering
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.
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.
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.
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
CREATE TABLE Student (ID int(6) NOT NULL UNIQUE, NAME varchar(10), ADDRESS
varchar(20), PRIMARY KEY(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));
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);
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).
This constraint ensures that a column can not have a NULL value. There can be
multiple NOT NULL constraint in any table.
15