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

LAB Manual 4th Sem

DBMS lab manual 4th sem

Uploaded by

shreekd2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
155 views

LAB Manual 4th Sem

DBMS lab manual 4th sem

Uploaded by

shreekd2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Department of Artificial Intelligence and Data Science Subject Code: BCS403

LAB Manual

Subject: DBMS Laboratory


A database management system (DBMS) is computer application software that
provides a way to manage data. The requirement of modern days is to have an automated
system that manages, modifies, and updates data accurately. This is achieved by a DBMS
in robust, correct, and non-redundant way. Structured Database Management Systems
(DBMS) based on relational and other models have long formed the basis for suchdatabases.
Consequently, Oracle, Microsoft SQL Server, Sybase etc. have emerged as leading
commercial systems while MySQL, PostgreSQL etc. lead in open source and free domain.
The Course allows students to apply the conceptual design model to construct thereal-world
requirement. Course gives familiarity of Database Concepts where students can analyse the
various constraints to populate the database and examine different working concepts of
DBMS to infer the most suitable pattern of documentation.
DBMS lab aims at practicing and achieving this aim by using MySQL. While also
gain capability to design database and its hierarchical structure for given real world
application.
Course Objectives
The objectives of this course are to make students to learn-
• Foundation knowledge in database concepts, technology, and practice to groom students into well-
informed database application developers.
• Strong practice in SQL programming through a variety of database problems.
• Develop database applications using front-end tools and back-end DBMS.

Course Outcomes
COs Description

1 Describe the basic elements of a relational database management system

2
Design entity relation for a given scenario

3 Apply various SQL statements for database manipulation

4 Analyse various normalization forms for the given application

5 Develop database application for the real world problem

6 Understand the concepts related to NoSQL databases

1
Syllabus

Subject: DBMS Lab Subject Code:BCS403


Note:
• Design, develop, and implement the specified queries for the following problems using Oracle,
MySQL, MS SQL Server, or any other DBMS under LINUX/Windows environment.
• Create Schema and insert at least 5 records for each table. Add appropriate database constraints.
1. Create a table called Employee & execute the following. Employee (EMPNO, ENAME, JOB, MANAGER_NO,
SAL, COMMISSION)
1. Create a user and grant all permissions to the user.
2. Insert the any three records in the employee table contains attributes EMPNO,ENAME JOB,
MANAGER_NO, SAL, COMMISSION and use rollback. Check the result.
3. Add primary key constraint and not null constraint to the employee table.
4. Insert null values to the employee table and verify the result

2. Create a table called Employee that contain attributes EMPNO, ENAME, JOB, MGR, SAL & execute the
following.
1. Add a column commission with domain to the Employee table.
2. Insert any five records into the table.
3. Update the column details of job
4. Rename the column of Employ table using alter command.
5. Delete the employee whose Empno is 105.

3. Queries using aggregate functions(COUNT,AVG,MIN,MAX,SUM),Group by,Orderby.


Employee(E_id, E_name, Age, Salary)

1. Create Employee table containing all Records E_id, E_name, Age, Salary.
2. Count number of employee names from employeetable
3. Find the Maximum age from employee table.
4. Find the Minimum age from employeetable.
5. Find salaries of employee in Ascending Order. 6. Find grouped salaries of employees.

4. Create a row level trigger for the customers table that would fire for INSERT or UPDATE or DELETE
operations performed on the CUSTOMERS table.
This trigger will display the salary difference between the old & new Salary.
CUSTOMERS(ID,NAME,AGE,ADDRESS,SALARY)

5. Create cursor for Employee table & extract the values from the table. Declare the variables ,Open the cursor &
extrct the values from the cursor. Close the cursor. Employee(E_id, E_name, Age, Salary)

6. Write a PL/SQL block of code using parameterized Cursor, that will merge the data available in the newly
created table N_RollCall with the data available in the table O_RollCall. If the data in the first table already
exist in the second table then that data should be skipped

7. Install an Open Source NoSQL Data base MangoDB & perform basic CRUD(Create, Read, Update & Delete)
operations. Execute MangoDB basic Queries using CRUD operations.

2
Assessment Details (both CIE and SEE)
The weightage of Continuous Internal Evaluation (CIE) is 50% and for Semester End Exam (SEE) is 50%. The minimum passing
mark for the CIE is 40% of the maximum marks (20 marks out of 50) and for the SEE minimum passing mark is 35% of the
maximum marks (18 out of 50 marks). A student shall be deemed to have satisfied the academic requirements and earned the
credits allotted to each subject/ course if the student secures a minimum of 40% (40 marks out of 100) in the sum total of the CIE
(Continuous Internal Evaluation) and SEE (Semester End Examination) taken together.
CIE for the theory component of the IPCC (maximum marks 50)
● IPCC means practical portion integrated with the theory of the course.
● CIE marks for the theory component are 25 marks and that for the practical component is 25 marks.
● 25 marks for the theory component are split into 15 marks for two Internal Assessment Tests (Two Tests, each of 15 Marks with
01-hour duration, are to be conducted) and 10 marks for other assessment methods mentioned in 22OB4.2.
The first test at the end of 40-50% coverage of the syllabus and the second test after covering 85-90% of the syllabus.
● Scaled-down marks of the sum of two tests and other assessment methods will be CIE marks for the theory component of IPCC
(that is for 25 marks).
● The student has to secure 40% of 25 marks to qualify in the CIE of the theory component of IPCC.

CIE for the practical component of the IPCC


● 15 marks for the conduction of the experiment and preparation of laboratory record, and 10 marks for the test to be conducted
after the completion of all the laboratory sessions.
● On completion of every experiment/program in the laboratory, the students shall be evaluated including viva-voce and marks
shall be awarded on the same day.
● The CIE marks awarded in the case of the Practical component shall be based on the continuous evaluation of the laboratory
report. Each experiment report can be evaluated for 10 marks. Marks of all experiments’ write-ups are added and scaled down to 15
marks.
● The laboratory test (duration 02/03 hours) after completion of all the experiments shall be conducted for 50 marks and scaled
down to 10 marks.
● Scaled-down marks of write-up evaluations and tests added will be CIE marks for the laboratory component of IPCC for 25
marks.
● The student has to secure 40% of 25 marks to qualify in the CIE of the practical component of the IPCC.
SEE for IPCC
Theory SEE will be conducted by University as per the scheduled timetable, with common question papers for the course (duration
03 hours)
1. The question paper will have ten questions. Each question is set for 20 marks.
2. There will be 2 questions from each module. Each of the two questions under a module (with a maximum of 3 subquestions),
should have a mix of topics under that module.
3. The students have to answer 5 full questions, selecting one full question from each module.
4. Marks scoredby the student shall be proportionally scaled down to 50 Marks
.The theory portion of the IPCC shall be for both CIE and SEE, whereas the practical portion will have a CIE component only.
Questions mentioned in the SEE paper may include questions from the practical component.
• Suggested Learning Resources:
Text Books:
1. Fundamentals of Database Systems, Ramez Elmasri and Shamkant B. Navathe, 7th Edition, 2017,
Pearson.
2. Database management systems, Ramakrishnan, and Gehrke, 3rd Edition, 2014, McGraw Hill
Activity Based Learning
(Suggested Activities in Class)/ Practical Based learning Mini Project:
• Project Based Learning

3
Department of Artificial Intelligence and Data Science Subject Code: BCS403

Index

Subject: DBMS Lab Subject Code: BCS403

SL. Page
Contents
No. No.

1 Basic Concepts of SQL 1-4

2 Lab Program-1 Create Employee Table & execute basic 5-6


SQL commands

3 Lab Program-2 Create Employee Table & execute basic 7


SQL commands

4 Lab Program-3 Queries using aggregate functions

5 Lab Program-4 Create a row level trigger for customer


table which will fire for insert or update or
delete

6 Lab Program-5 Create cursor for employee table & extract


the values from the table

7 Lab Program-6 Create cursor for employee table &


extract the values from the table

8 Lab Program-7 Create cursor for employee table &


extract the values from the table

9 Viva Questions & Answers

4
BASIC CONCEPTS OF SQL
Introduction to SQL
SQL stands for “Structured Query Language” and can be pronounced as “SQL” or “sequel
– (Structured English Query Language)”. It is a query language used for accessing and modifying
information in the database. IBM first developed SQL in 1970s. Also it is an ANSI/ISO standard.
It has become a Standard Universal Language used by most of the Relational Database Management
Systems (RDBMS). Some of the RDBMS systems are: Oracle, Microsoft SQL server, Informix
etc.Most of these have provided their own implementation thus enhancing its feature and making
it a powerful tool. Few of the SQL commands used in SQL programming are SELECT
Statement,UPDATE Statement, INSERT INTO Statement, DELETE Statement, WHERE Clause,
ORDER BY Clause, GROUP BY Clause, ORDER Clause, Joins, Views,GROUP Functions,
Indexes etc.

DataBase: An organized collection of data stored in an electronic format.

Database Management System: It is a system software for creating & managing databases

SQL: It stands for Structured Query Launguage, which is a standard language for storing &
Managing data in Relational database management systems.

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, for example, you can create tables, add data to tables, or
modify data, drop the table, set permissions for users.

Types of SQL commands

1. DDL (Data Definition Language):- Create, Alter, Drop, Truncate

2. DML(Data Manipulation Language):- Insert, Update, Delete

3. DQL(Data Query Language):- Select

4. DCL(Data Control Language):-Grant, Revoke

5. TCL(Transaction Control Language):- Commit, Savepoint, Rollback

1
CREATE TABLE Statement
The CREATE TABLE Statement is used to create tables to store data. Integrity Constraints like
primary key, unique key and foreign key can be defined for the columns while creating the table.

The Syntax for the CREATE TABLE Statement is:

CREATE TABLE
table_name
(Column_name1 datatype constraint,
column_name2 datatype,
column_nameN datatype);

The Syntax for the INSERT Statement: - used to insert records in to the table.

INSERT INTO
table_name
(Column_name1, column_name2…..)
VALUES
(value1, value2,...);

The Syntax for the ALTER Statement:- used to add, delete or modify columns in a table.
Alter table table_name

Add/Drop Column_name datatype;

UPDATE Statement: - This allows the user to update the particular column value using the where clause condition.

UPDATE table_name SET


Column_name= <value>
where condition;

DROP TABLE:- Delete Objects from the Database


DROP TABLE
table_name;

TRUNCATE TABLE:- Remove all records from a table, including all spaces allocated for the records are removed.

TRUNCATE TABLE
table_name;

DELETE :- This allows you to delete the particular column values using where clause condition

Delete from table_name where condition;

2
SQL Data Types:

char(size) Fixed-length character string. Size is specified in parenthesis. Max 255


bytes.
Varchar2(size) Variable-length character string. Max size is specified in parenthesis.

number(size) or int
Number value with a max number of column digits specified in parenthesis.

Date Date value in “dd-M-YY” Eg., ‟07-jul-2004‟

number (size, d) or real Number value with a maximum number of digits of "size" total, with a
maximum number of "d" digits to the right of the decimal.

SQL Integrity Constraints:


Integrity Constraints are used to apply business rules for the database tables. The constraints
available in SQL are Foreign Key, Primary key, Not Null, Unique, Check, Default.
Constraints can be defined in two ways:
1. The constraints can be specified immediately after the column definition. This is called column-level
definition.
2. 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 to define a Primary key at column level:

Column_namedatatype [CONSTRAINT constraint_name] PRIMARY KEY

Syntax to define a Primary key at table level:

[CONSTRAINT constraint_name] PRIMARY KEY(column_name1,

column_name2,..)

2) Foreign key or Referential Integrity:


This constraint identifies any column referencing 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.
3
Syntax to define a Foreign key at column level:

[CONSTRAINT constraint_name] REFERENCES

referenced_table_name(column_name)

3) Not Null Constraint:


This constraint ensures all rows in the table contain a definite value for the column which is
specified as not null. Which means a null value is not allowed.
Syntax to define a Not Null constraint:
[CONSTRAINT constraint name] NOT NULL

4) Unique Key:
This constraint ensures that a column or a group of columns in each row have a distinct value.
A column(s) can have a null value but the values cannot be duplicated.
Syntax to define a Unique key at column level:
[CONSTRAINT constraint_name] UNIQUE

Syntax to define a Unique key at table level:


[CONSTRAINT constraint_name] UNIQUE(column_name)

5) Check Constraint:
This constraint defines a business rule on a column. All the rows must satisfy this rule. The
constraint can be applied for a single column or a group of columns.
Syntax to define a Check constraint:

[CONSTRAINT constraint_name] CHECK (condition)

Rollback command
This command restores the database to last committed state. It is also use with savepoint command
to jump to a savepoint in a transaction.
Savepoint command

savepoint command is used to temporarily save a transaction so that you can rollback to that point
whenever necessary.
4
Program 1

Create a table called Employee & execute the following.


Employee (EMPNO, ENAME, JOB, MANAGER_NO, SAL, COMMISSION)
1. Create a user and grant all permissions to the user.
2. Insert the any three records in the employee table contains attributes
EMPNO,ENAME JOB, MANAGER_NO, SAL, COMMISSION and use rollback. Check
the result.
3. Add primary key constraint and not null constraint to the employee table.
4. Insert null values to the employee table and verify the result

CREATE TABLE Employee


(
EMPNO NUMBER(5),
ENAME VARCHAR2(50),
JOB VARCHAR2(50),
MANAGER_NO NUMBER(5),
SAL NUMBER(10, 2),
COMMISSION NUMBER(10, 2)
);

1. Create a user and grant all permissions to the user.


Connect sys as sysdba;
Create user username idenitifed by password

Ex: create user cit identified by cit123;

GRANT CONNECT, RESOURCE TO <username>;

GRANT SELECT, INSERT, UPDATE, DELETE ON <table_name> TO


<username>;

GRANT CREATE TABLE, CREATE SEQUENCE TO <username>;

grant all privileges to username identified by password;

COMMIT;

Disconnect;

5
2. Insert the any three records in the employee table contains attributes
EMPNO, ENAME JOB, MANAGER_NO, SAL, COMMISSION and use
rollback. Check the result.

INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO,


SAL, COMMISSION)
VALUES (1, 'John Doe', 'Manager', NULL, 5000, 1000);

INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO,


SAL, COMMISSION)
VALUES (2, 'Jane Smith', 'Developer', 1, 4000, NULL);

INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO,


SAL, COMMISSION)
VALUES (3, 'Alice Johnson', 'Analyst', 1, 3500, 500);

-- Rollback the transaction


ROLLBACK;

SELECT * FROM Employee;

3. Add primary key constraint and not null constraint to the employee table.

ALTER TABLE Employee


ADD CONSTRAINT pk_employee PRIMARY KEY (empno);

-- Add NOT NULL constraint to ENAME, JOB, and SAL columns

ALTER TABLE Employee


MODIFY (ENAME VARCHAR2(50) NOT NULL,
JOB VARCHAR2(50) NOT NULL,
SAL NUMBER (10, 2) NOT NULL);

4. Insert null values to the employee table and verify the result.
INSERT INTO Employee(EMPNO, ENAME, JOB, MANAGER_NO,
SAL, COMMISSION)
VALUES (4, NULL, 'Tester', 1, NULL, NULL);

INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO,


SAL, COMMISSION)
VALUES (5, 'Jack Smith', NULL, 1, NULL, NULL);

6
Program 2
Create a table called Employee that contain attributes EMPNO, ENAME, JOB, MGR,
SAL & execute the following.
1. Add a column commission with domain to the Employee table.
2. Insert any five records into the table.
3. Update the column details of job
4. Rename the column of Employ table using alter command.
5. Delete the employee whose Empno is 105.

1. Creating the Employee table

CREATE TABLE Employee2


(
EMPNO INT PRIMARY KEY,
ENAME VARCHAR(50),
JOB VARCHAR(50),
MGR INT,
SAL DECIMAL(10, 2)
);

2. Adding a column commission to the Employee table

ALTER TABLE Employee2


ADD commission DECIMAL(10, 2);

3. Inserting five records into the table

INSERT INTO Employee2 (EMPNO, ENAME, JOB, MGR, SAL, commission)


VALUES (101, 'John Doe', 'Manager', NULL, 50000.00, 1000.00),
(102, 'Jane Smith', 'Developer', 101, 40000.00, 800.00),
(103, 'Mike Johnson', 'Analyst', 101, 35000.00, 700.00),
(104, 'Emily Brown', 'Designer', 102, 38000.00, 750.00),
(105, 'David Lee', 'Tester', 103, 32000.00, 600.00);

4. Updating the column details of job.


For example: changing 'Manager' to 'Project Manager'

UPDATE Employee2
SET JOB = 'Project Manager'
WHERE JOB = 'Manager';

5. Renaming the column of Employee table using ALTER command.

ALTER TABLE Employee


RENAME COLUMN MGR TO MANAGER_ID;

6. Deleting the employee whose Empno is 105.

DELETE FROM Employee2 WHERE EMPNO = 105;


7

You might also like