0% found this document useful (0 votes)
11 views14 pages

Himanshu Dbms PDF

Uploaded by

mshivraj357
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)
11 views14 pages

Himanshu Dbms PDF

Uploaded by

mshivraj357
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/ 14

A

Practical File

On

Database Management Systems Lab


Submitted In Partial Fulfilment of the requirements for the award of degree of Bachelor of
Technology
In
Computer Science & Engineering
From

Engineering College Bikaner

Affiliated to

Bikaner Technical University, Bikaner


(Session: 2022-2026)

Submitted By: Himanshu Submitted to


University Roll No: 22EEBCS034 Dr Dhanroopmal Nagar
Assistant Professor
Department of IT
DBMS Practical File Session 2022-26
INDEX

S.N Name of Practical Date Signature


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.
Write a SQL statement for implementing ALTER,
3.
UPDATE and DELETE.
Write the queries to implement the joins.
4
Write the query for implementing the following functions:
. MAX(), MIN(), AVG() and COUNT().
5 Write the query to implement the concept of Integrity
6. constraints.
.
Write the query to create the views.
7 Perform the queries for triggers.
. Perform the following operations for demonstrating the
8 insertion, updation and deletion.
Using the referential integrity constraints.
.
10. Write the query for creating the users and their role.
9
11. ERD
.
12.

1
DBMS Practical File Session 2022-26

Practical 1: Design a Database and create required tables.

CREATE DATABASE MyCollege;


SHOW DATABASES;
USE MyCollege;

CREATE TABLE Students (


RollNo INTEGER,
Name CHAR(20),
Age INTEGER,
DOB VARCHAR(20),
City CHAR(20),
PhoneNo INTEGER
);

CREATE TABLE Marks (


RollNo INT,
Name CHAR(20),
Maths INT,
Physics INT,
Chemistry INT,
Communication INT,
Fundamentals INT
);

2
DBMS Practical File Session 2022-26

Practical 2: Apply Constraints like Primary Key, Foreign Key, Not Null to the tables.

CREATE TABLE Students (


RollNo INTEGER PRIMARY KEY,
Name CHAR(20) NOT NULL,
Age INTEGER NOT NULL,
DOB VARCHAR(20) NOT NULL,
City CHAR(20),
PhoneNo INTEGER
);

CREATE TABLE Marks (


RollNo INT PRIMARY KEY,
Name CHAR(20),
Maths INT,
Physics INT,
Chemistry INT,
Communication INT,
Fundamentals INT
);

3
DBMS Practical File Session 2022-26

Practical 3: Write SQL Statement for ALTER, UPDATE and DELETE.

ALTER TABLE Students ADD COLUMN LastName VARCHAR(20) NOT NULL;

UPDATE Students SET City = ‘Jaipur’ WHERE Name = ‘Peeyush’;

DELETE FROM Students WHERE Name = ’Rahul’;

4
DBMS Practical File Session 2022-26

Practical 4: Write the queries to implement the joins.

SELECT Students.RollNo, Students.Name, Marks.Maths, Marks.Fundamentals


FROM Students
JOIN Marks
ON Students.RollNo = Marks.RollNo;

5
DBMS Practical File Session 2022-26

Practical 5: Write the query for implementing the following functions: MAX (), MIN (), AVG
() and COUNT ().

SELECT max(Fundamentals) FROM Marks;

SELECT min(Chemistry) FROM Marks;

SELECT avg(Maths) FROM Marks;

SELECT count(RollNo) FROM Students;

6
DBMS Practical File Session 2022-26

Practical 6: Write the query to implement the concept of Integrity constraints.

CREATE TABLE Teachers (


id INT PRIMARY KEY,
Name CHAR(30) NOT NULL,
Subject CHAR(30) UNIQUE,
Salary INT DEFAULT 30000
);

7
DBMS Practical File Session 2022-26

Practical 7: Write the query to create the views.

CREATE VIEW BikanerStudents AS


SELECT RollNo, Name
FROM Students
WHERE City=’Bikaner’;

SELECT * FROM BikanerStudents;

8
DBMS Practical File Session 2022-26

Practical 8: Perform the queries for triggers.

CREATE TRIGGER Check_exp BEFORE INSERT


ON Teachers
FOR EACH ROW
IF NEW.Experience < 7 THEN
SIGNAL SQLSTATE '50001'
SET message_text='ERROR: Experience More than 7 Years Required!';
END IF;
END;

For Deleting Trigger:

DROP TRIGGER Check_exp;

9
DBMS Practical File Session 2022-26

Practical 9: Perform the following operation for demonstrating the insertion, updation and
deletion.

Insertion:

INSERT INTO Students VALUES(101, "Peeyush", 19, "26/Feb/2005", "Bikaner", 1897645321);

INSERT INTO Students (Name, Age, DOB, City, PhoneNo) VALUES


("Varun", 21, "01/Sept/2003", "Bikaner", 1276543251),
("Rahul", 20, "04/Mar/2004", "Jaipur", 1254356689),
("Parveen", 18, "10/Nov/2006", "Jhunjhunu", 1289528251);

Updation:

UPDATE Students SET City='Jaipur' WHERE Name='Peeyush';

Deletion:

DELETE FROM Students WHERE Name='Peeyush';

10
DBMS Practical File Session 2022-26

Practical 10: Using the referential integrity constraints.

CREATE TABLE Marks (


RollNo INTEGER,
Name CHAR(20),
Maths INT,
Physics INT,
Chemistry INT,
Communication INT,
Fundamentals INT,
FOREIGN KEY (RollNo) REFERENCES Students(RollNo)
);

Adding new row in Marks table while not exist in Students table:

Deleting row from Students Table while existing in Marks Table:

11
DBMS Practical File Session 2022-26

Practical 11: Write the query for creating the users and their role.

Creating Users:

CREATE USER 'Peeyush' IDENTIFIED BY 'password';

Creating Roles:

CREATE ROLE auditors AUTHORIZATION Peeyush;


GO

12
DBMS Practical File Session 2022-26

Practical 12: ERD

13

You might also like