DBMS Lab Manual
DBMS Lab Manual
Course Objectives:
1. To learn the ER data model, database design and normalization
2. To Learn SQL basics for data definition and data manipulation
Course Outcomes: After the completion of this course, the students would be able to
1. Demonstrate ER Modeling concepts to design the Database
2. Apply integrity constraints on a database
3. Make use of DDL, DML, DCL, TCL commands in creation and manipulation of
Database
4. Implementation of database queries using PL/SQL
5. Experiment with triggers to maintain the referential integrity of data
LIST OF EXPERIMENTS:
1. Design ER Model for a given application & Convert ER model to Relational Model.
2. Creating users - roles and Granting privileges.
3. Creating and altering tables for various relations in SQL using Integrity Constraints.
4. Implementing queries in SQL using
4.1 Insertion
4.2 Retrieval (operations like union - intersect - minus - in - exists - group by and having)
4.3 Updation
4.4 Deletion
Case Study – Give options to the students to do case study on their own / faculty may give
list of case study in beginning of the semester
Experiment1: Designing ER Model and Conversion to Relational Model for Library Management
System
Tools Used
Objective:
To design an Entity-Relationship (ER) model and convert it into a Relational Model for a Bus
Management System.
Requirements:
Understanding of Entity-Relationship (ER) modeling concepts.
Knowledge of relational database design principles.
Familiarity with notation standards for ER diagrams.
Experiment:
1. Entity-Relationship (ER) Model:
Entities:
Bus: Represents a bus in the system.
Attributes: BusID (Primary Key), Route, Capacity, Type.
Driver: Represents a driver associated with a bus.
Attributes: DriverID (Primary Key), Name, LicenseNumber.
Passenger: Represents a passenger using the bus service.
Attributes: PassengerID (Primary Key), Name, Age, ContactInfo.
Route: Represents a route followed by buses.
Attributes: RouteID (Primary Key), Source, Destination, Distance.
Ticket: Represents a ticket issued to a passenger for a bus journey.
Attributes: TicketID (Primary Key), PassengerID (Foreign Key), BusID (Foreign Key), RouteID
(Foreign Key), Date, Fare.
Relationships:
Bus-Driver: One-to-One relationship between Bus and Driver entities.
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE LAB MANUAL (AIDS-II-II)
-- Assuming you have a table in a schema that you wish to grant access to, replace
'your_schema.your_table' with the actual schema and table name
-- Grant SELECT, INSERT, and UPDATE privileges on a specific table to the Manager role
GRANT SELECT, INSERT, UPDATE ON your_schema.your_table TO Manager;
-- (Optional) Check the privileges of UserA -- this step requires querying the database's system views or
being logged in as UserA
Example 1:
Suppose we want to create a role called 'staff' with SELECT privilege on a table called 'books' and grant
this role to a user named 'john'. We can execute the following SQL commands:
CREATE ROLE staff;
GRANT SELECT ON library.books TO staff;
GRANT staff TO 'john'@'localhost';
Conclusion:
Creating users, defining roles, and granting privileges are essential tasks in database management. By
following these steps, database administrators can control access to database objects and ensure data
security and integrity.
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE LAB MANUAL (AIDS-II-II)
EXAMPLE 2:
-- Create UserA and UserB
CREATE USER UserA IDENTIFIED BY password1;
CREATE USER UserB IDENTIFIED BY password2;
-- Grant SELECT, INSERT, UPDATE, and DELETE privileges on the 'employees' table to the Manager
role
GRANT SELECT, INSERT, UPDATE, DELETE ON hr.employees TO Manager;
-- Grant SELECT, INSERT, UPDATE, DELETE privileges on the 'employees' table to the 'Manager' role
GRANT SELECT, INSERT, UPDATE, DELETE ON hr.employees TO Manager;
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE LAB MANUAL (AIDS-II-II)
Experiment3. Creating and altering tables for various relations in SQL using Integrity
Constraints
Objective: Learn how to create and alter tables in SQL with integrity constraints to maintain data
consistency.
Tasks:
Create a Table for Employees:
Create a table named employees with the following columns:
employee_id (Primary Key)
first_name
last_name
email
hire_date
job_id
salary
Alter Table Structure:
Add a new column named department_id to the employees table to store department information.
Define a foreign key constraint on the department_id column referencing a departments table (if
available) or a predefined list of department IDs.
-- Replace 'jobs' with the actual table name or list of job codes if available
ALTER TABLE employees
ADD CONSTRAINT fk_job_id FOREIGN KEY (job_id) REFERENCES jobs(job_id);