DBMS Lab Record
DBMS Lab Record
DBMS Lab Record
12 04/11/24 Project 67
5
Experiment No:1 Date:23/07/24
Aim:
Program 1:
The requirement:
A hospital token management system to make a token for the patient which keeps track
of doctors,doctors department,patient name,patient age,patient gender.
When the patient enters the system the system provides a guided way to register the
patient then book the doctor as a token number in return.
Database Design
Patient(PId,PName,PAge,PGender)
DDL COMMANDS:
6
mysql> create table Doctor (doctorID int primary key, Dname varchar(255) not null,
Ddept varchar(255) not null );
mysql> create table Patient (PID int primary key, Pname varchar(255) not null, Page int
not null, PGender varchar(10) not null );
mysql> create table Token (tokenID int primary key, tdate DATE not null, doctorID int,
PID int, foreign key (doctorID) references Doctor(doctorID), foreign key (PID)
references Patient(PID) );
Result:
Program 2:
Create an ER diagram for the above database design .
ER DIAGRAM :
Result:
ER diagram for the above database design created.
7
Experiment No:2 Date:05/08/24
AIM:
Practice SQL commands for DML (insertion, updating, altering, deletion of data,
and viewing/querying records based on condition in databases)
Note: Emp_id should start with ‘E’ in Emp table and emp_id in works table must be the
emp_id from emp table . emp_id and manager_id in manages table must be the emp_id
from emp table
II. Alter table emp add a constraint that emp_name cannot be null
8
Consider the employee database created for the following questions
b. Find all employees in the database who live in the same cities as the companies for
c. Find all employees and their managers in the database who live in the same cities and
on the same street number as do their managers.
d. Find all employees who earn more than the average salary of all employees of their
company.
e. Find the company that pay least total salary along with the salary paid.
h. Find those companies whose employees earn a higher salary, on average than the
i. Query to find name and salary of all employees who earn more than each employee
of ‘Indian Bank’
DDL:
9
mysql> use cmpy;
Database changed
mysql> CREATE TABLE emp (
-> emp_id VARCHAR(10) PRIMARY KEY CHECK(emp_id LIKE 'E%'),
-> emp_name VARCHAR(50) NOT NULL,
-> Street_No VARCHAR(10),
-> city VARCHAR(50)
-> );
Query OK, 0 rows affected (0.04 sec)
10
Records: 0 Duplicates: 0 Warnings:0
11
Records: 4 Duplicates: 0 Warnings: 0
12
Query:
emp_name
John
Alice
b. Find all employees in the database who live in the same cities as the companies for
which they work.
c. Find all employees and their managers in the database who live in the same cities
and on the same street number as do their managers.
13
mysql> SELECT e1.emp_name AS Employee, e2.emp_name AS Manager
-> FROM emp e1
-> JOIN manages m ON e1.emp_id = m.emp_id
-> JOIN emp e2 ON m.manager_id = e2.emp_id
-> WHERE e1.city = e2.city AND e1.Street_No = e2.Street_No;
+-----------+------------+
| Employee | Manager |
+-----------+------------+
| John | Raj |
| Tom | John |
+-----------+------------+
2 rows in set (0.00 sec)
d. Find all employees who earn more than the average salary of all employees of
their company.
e. Find the company that pays the least total salary along with the salary paid.
mysql> SELECT company_name, SUM(salary) AS total_salary
-> FROM works
14
-> GROUP BY company_name
-> ORDER BY total_salary ASC
-> LIMIT 1;
+-------------------+-----------------+
| company_name | total_salary |
+-------------------+-----------------+
| HDFC | 70000.00 |
+-------------------+-----------------+
1 row in set (0.00 sec)
h. Find those companies whose employees earn a higher salary, on average, than the
average salary at Indian Bank.
15
i. Query to find the name and salary of all employees who earn more than each
employee of ‘Indian Bank’.
Result:
DML Statements have been executed.
16
Experiment No:3 Date:12/08/24
AIM
1. Make a list of all project numbers for projects that involve an employee whose last
name is 'Raj' as a worker or as a manager of the department that controls the project.
2. Retrieve the name of each employee who has a dependent with the same name as
the employee.
17
3. Retrieve the names of employees who have no dependents.
4. Retrieve the social security numbers of all employees who work on project
number 1, 2, or 3.
DDL:
18
mysql> update cascade,foreign key(PNO) references PROJECT(PNUMBER) on delete
cascade on update cascade);
Query OK, 0 rows affected (0.02 sec)
19
mysql> INSERT INTO DEPT_LOCATIONS (DNUMBER, DLOCATION)
-> VALUES
-> (1, 'Mumbai'),
-> (2, 'Delhi'),
-> (3, 'Bangalore'),
-> (4, 'Chennai'),
-> (5, 'Kerala');
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
20
INSERT INTO DEPENDENT (ESSN, DEPENDENT_NAME, SEX, BDATE,
RELATIONSHIP) VALUES (111111111, 'John', 'M', '2010-01-01', 'Son'), (222222222
, 'Raj', 'M', '2015-05-15', 'Son'), (333333333, 'Mira', 'F', '2012-03-10', 'Daughter'),
(444444444, 'Sanjay', 'M', '1992-04-20', 'Self'), (5555
), (888888888, 'Ravi', 'M', '2011-08-19', 'Son');
Query OK, 8 rows affected (0.01 sec)
Records: 8 Duplicates: 0 Warnings: 0
Query:
1. Make a list of all project numbers for projects that involve an employee
whose last
+---------------+
| PNUMBER |
+--------------+
| 1 |
| 2 |
| 3 |
+--------------+
2.Retrieve the name of each employee who has a dependent with the same name as
the employee.
21
+------------+
| FNAME |
+------------+
| John |
| Raj |
| Mira |
| Sanjay |
| Amit |
+----------+
4.Retrieve the social security numbers of all employees who work on project number
1, 2, or 3.
22
5.Retrieve the names of all employees who do not have supervisors.
+--------------------+----------------+---------------+-----------------------+
| DNAME | DNUMBER | MGRSSN | MGRSTARTDATE |
+--------------------+----------------+---------------+------------------------+
| Research | 1 | 111111111 | 2010-01-01 |
| Administration | 2 | 444444444 | 2011-02-15 |
| IT | 4 | 555555555 | 2013-04-20 |
| HR | 5 | 666666666 | 2014-05-25 |
+-------------------+----------------+---------------+------------------------+
23
mysql> SELECT * FROM PROJECT;
+------------+---------------+------------------+---------+
| PNAME | PNUMBER | PLOCATION | DNUM |
+------------+---------------+-----------------+----------+
| Alpha | 1 | Mumbai | 1 |
| Beta | 2 | Delhi | 2 |
| Delta | 4 | Chennai | 4 |
| Epsilon | 5 | Kerala | 5 |
| Zeta | 10 | Kerala | 5 |
+------------+--------------+------------------+----------+
5 rows in set (0.00 sec)
Result:
Different nested and join queries have been executed
24
Experiment No:4 Date:19/08/24
AIM
1. Find the maximum salary, the minimum salary, and the average salary among
employees who work for the 'Research' department.
2. For each department, retrieve the department number, the number of employees in
the department, and their average salary.
3. For each project, retrieve the project number, project name, and the number of
employees who work on that project.
4. For each project on which more than two employees work, retrieve the project
number, project name, and the number of employees who work on that project.
7. Retrieve a list of employees and the projects each works in, ordered by the
employee's department, and within each department ordered alphabetically by employee
last name.
8. Retrieve the details of the employee getting the third highest salary.
25
10. Find the average age of employees.
Query:
1.Find the maximum salary, the minimum salary, and the average salary among
employees who work for the 'Research' department.
2.For each department, retrieve the department number, the number of employees
in the department, and their average salary.
26
3.For each project, retrieve the project number, project name, and the number of
employees who work on that project.
SELECT P.PNUMBER,P.PNAME,COUNT(W.ESSN) FROM PROJECT AS P JOIN
WORKS_ON AS W ON P.PNUMBER=W.PNO GROUP BY P.PNUMBER;
+---------------+------------- +--------------------------+
| PNUMBER | PNAME | COUNT(W.ESSN) |
+---------------+------------- +-------------------------+
| 1 | Alpha | 3 |
| 2 | Beta | 1 |
| 4 | Delta | 1 |
| 5 | Epsilon | 1 |
+---------------+--------------+-------------------------+
4 rows in set (0.01 sec)
4.For each project on which more than two employees work, retrieve the project
number, project name, and the number of employees who work on that project.
27
2 rows in set (0.00 sec)
7.Retrieve a list of employees and the projects each works in, ordered by the
employee's department, and within each department ordered alphabetically by
employee last name.
+------------+--------------+---------------+----------------------+
| FNAME | PNAME | DNUMBER | DNAME |
+------------+---------- --+----------------+--------------------- +
| Mohit | Beta | 2 | Administration |
| Sanjay | Alpha | 2 | Administration |
| Amit | Epsilon | 5 | HR |
| Anita | Alpha | 5 | HR |
| Rani | Delta | 4 | IT |
| John | Alpha | 1 | Research |
+-------------+------------+-----------------+------------------—-+
6 rows in set (0.00 sec)
28
8.Retrieve the details of the employee getting the third highest salary.
29
SELECT E.SSN,E.FNAME FROM EMPLOYEE AS E WHERE
DAYOFMONTH(BDATE)=01;
+-----------------+-----------+
| SSN | FNAME |
+----------------+------------+
| 111111111 | John |
+----------------+------------+
1 row in set (0.00 sec)
Result:
DML Statements have been executed.
30
Experiment No:5 Date:24/08/24
AIM
Practice of SQL commands for creation of views and triggers
2. Create a trigger to check , whether an employee’s salary is greater than the salary of
his or her direct supervisor in the COMPANY database.
Query:
31
CREATE TABLE ERROR(SSN INT,SUPERSSN INT,FOREIGN KEY(SSN) REFERENCES
EMPLOYEE(SSN),FOREIGN KEY(SUPERSSN) REFERENCES EMPLOYEE(SSN));
Query OK, 0 rows affected (0.03 sec)
DELIMITER //
mysql> CREATE TRIGGER CHECK_SALARY
-> AFTER INSERT ON EMPLOYEE
-> FOR EACH ROW
-> BEGIN
-> IF NEW.SUPERSSN IS NOT NULL THEN
-> IF(SELECT SALARY FROM EMPLOYEE WHERE
SSN=NEW.SUPERSSN)<NEW.SALARY THEN
-> INSERT INTO ERROR(SSN,SUPERSSN) VALUES(NEW.SSN,NEW.SUPERSSN);
-> SIGNAL SQLSTATE '45000'
-> SET MESSAGE_TEXT = "EMPLOYEE SALARY CANNOT EXCEED SUPERVISOR
SALARY!";
-> END IF;
-> END IF;
-> END //
Result:
Views and Triggers have been executed.
32
Experiment No:6 Date:02/09/24
AIM
33
mysql> Select sqrt(16);
+----------+
| sqrt(16) |
+----------+
| 4 |
+----------+
1 row in set (0.00 sec)
34
+--------------------+
| round(22.897,2) |
+---------------------+
| 22.90 |
+---------------------+
1 row in set (0.00 sec)
35
SELECT CURRENT_DATE FROM DUAL;
+-----------------------+
| CURRENT_DATE |
+-----------------------+
| 2024-11-04 |
+-----------------------+
1 row in set (0.00 sec)
36
mysql> select month(curdate());
+---------------------+
| month(curdate()) |
+---------------------+
| 10 |
+----------------------+
1 row in set (0.00 sec)
Result:
Aggregate and Built-in functions have been executed.
37
Experiment No:7 Date:23/09/24
AIM
COMMIT command
COMMIT command is used to permanently save any transaction into the database.
When we use any DML command like INSERT, UPDATE or DELETE, the changes
made by these commands are not permanent, until the current session is closed, the
changes made by these commands can be rolled back.
To avoid that, we use the COMMIT command to mark the changes as permanent.
COMMIT;
ROLLBACK command
38
This command restores the database to last commited state. It is also used with
SAVEPOINT command to jump to a savepoint in an ongoing transaction.
If we have used the UPDATE command to make some changes into the database, and
realise that those changes were not required, then we can use the ROLLBACK command
to rollback those changes, if they were not commited using the COMMIT command.
ROLLBACK TO savepoint_name;
SAVEPOINT command
SAVEPOINT command is used to temporarily save a transaction so that you can rollback
to that point whenever required.
SAVEPOINT savepoint_name;
Id Name
1 Abhi
2 Adam
4 Alex
39
COMMIT;
start transaction;
SAVEPOINT A;
SAVEPOINT B;
SAVEPOINT C;
Id Name
1 Abhi
2 Adam
4 Alex
5 Abhijit
40
6 Chris
7 Bravo
ROLLBACK TO B;
Id Name
1 Abhi
2 Adam
4 Alex
5 Abhijit
Result:
SQL TCL Commands have been executed.
41
Experiment No:8 Date:27/09/24
PL/SQL Programs
AIM
Implementation of various control structures like IF-THEN, IF-THEN-ELSE,
IF-THEN-ELSIF, CASE, WHILE using PL/SQL.
PL/SQL PROGRAMS
begin
dbms_output.put_line('hello world');
end ;
/
output:
Statement processed.
hello world
declare
var1 integer;
var2 integer;
var3 integer;
begin
var1:=5;
var2:=6;
var3:=var1+var2;
dbms_output.put_line(var3);
end ;
/
output:
Statement processed.
11
42
3. PL/SQL code to find reverse of a number.
declare
n number;
i number;
rev number:=0;
r number;
begin
n:=678;
while n>0
loop
r:=mod(n,10);
rev:=(rev*10)+r;
n:=trunc(n/10);
end loop;
dbms_output.put_line('reverse is:'||rev);
end;
Output:
Statement processed.
reverse is:876
declare
n number;
i number;
flag number;
begin
i:=2;
flag:=1;
n:=11;
for i in 2..n/2
loop
if mod(n,i)=0
then
flag:=0;
43
exit;
end if;
end loop;
if flag=1
then
dbms_output.put_line(n||' is prime');
else
dbms_output.put_line(n||' is not prime');
end if;
end;
output:
Statement processed.
11 is prime
declare
str1 varchar(50):='DATABASE';
str2 varchar(50);
len number;
i number;
begin
len:=length(str1);
for i in reverse 1..len
loop
str2:=str2||substr(str1,i,1);
end loop;
dbms_output.put_line('Reverse of string is:'||str2);
end ;
/
output:
Statement processed.
Reverse of string is:ESABATAD
44
6. PL/SQL code to find the largest of three numbers.
declare
a number:=10;
b number:=12;
c number:=5;
begin
dbms_output.put_line('a='||a||',b='||b||',c='||c);
if a>b and a>c
then
dbms_output.put_line(a||' is largest');
else
if b>a and b>c
then
dbms_output.put_line(b||' is largest');
else
dbms_output.put_line(c||' is largest');
end if;
end if;
end ;
/
output:
Statement processed.
a=10,b=12,c=5
12 is largest
7.PL/SQL code to use CASE statement to print a color based on the given code.
declare
color varchar(2):='G';
begin
45
case color
end case;
end ;
output:
Statement processed.
Green
8.PL/SQL code to use CASE statement to print the result based on grade.
declare
grade varchar(2):='B';
begin
case grade
when 'A' then dbms_output.put_line('Excelent');
when 'B' then dbms_output.put_line('Very Good');
when 'C' then dbms_output.put_line('Good');
when 'D' then dbms_output.put_line('Fair');
when 'F' then dbms_output.put_line('Poor');
else dbms_output.put_line('No Such Grade');
end case;
end ;
/
output:
46
Statement processed.
Very Good
Result:
PL/SQL Programs have been executed .
47
Experiment No:9 Date:27/09/24
AIM
1. Increment the salary of the employee with ssn=100, by Rs 2000, if his experience
>5years. Otherwise increment his salary by Rs 1000.
2.Increment the salary of the employees by 10% if his experience > 5years. Otherwise
increment his salary by Rs 500. Use Cursor.
3.From the above table retrieve the details of employee with ssn=200. Raise an exception
if such an employee does not exist.
DDL:
48
insert into employee values('Raja',200,11000,5);
1 row(s) inserted.
insert into employee values('Anu',300,12000,6);
1 row(s) inserted.
4 rows selected.
PL/SQL Programs:
1. Increment the salary of the employee with ssn=100, by Rs 2000, if his experience
>5years. Otherwise increment his salary by Rs 1000.
declare
exp employee.experience%type;
sal employee.salary%type;
begin
select experience,salary into exp,sal from employee where ssn=100;
if exp>5 then
sal:=sal+2000;
else
sal:=sal+1000;
end if;
update employee set salary=sal where employee.ssn=100;
end ;
/
Output:
Statement processed.
49
select * from employee where ssn=100;
Output:
Result Set 3
2.Increment the salary of the employees by 10% if his experience > 5years.
Otherwise increment his salary by Rs 500. Use Cursor.
declare
exp employee.experience%type;
sal employee.salary%type;
ename employee.ename%type;
ssn employee.ssn%type;
cursor crs is select ename,ssn,experience,salary from employee for update of
salary;
begin
open crs;
loop
fetch crs into ename,ssn,exp,sal;
exit when crs%notfound;
if exp>5 then
sal:=sal+(sal*0.1);
else
sal:=sal+500;
end if;
update employee set salary=sal where current of crs;
dbms_output.put_line(ename||''||ssn||''||exp||''||sal||'');
end loop;
end ;
/
output:
Statement processed.
Rani100511500
Anil400713200
Raja200511500
Anu300613200
50
select * from employee;
output:
Result Set 4
3.From the above table retrieve the details of employee with ssn=200. Raise an
exception if such an employee does not exist.
declare
sn int;
begin
select ssn into sn from employee where ssn = 500;
exception
when no_data_found then
dbms_output.put_line('No such Employee Exits');
end ;
/
output:
Statement processed.
No such Employee Exits
Result:
PL/SQL Cursors and Exceptions have been executed.
51
Experiment No:10 Date:30/09/24
AIM
1. Write a procedure to find out the name of the employee having maximum salary.
2. Write a procedure to accept the department no and print the details of its manager.
4. Create a procedure to give Rs.1000 hike in the salary of all the employees who work
in Research department. Update the table accordingly.
5. Create a trigger to update the total salary of a department when a new employee is
hired.
6. The company has a policy that the minimum salary for an employee is 10000.
Create a trigger to check if the salary entered while inserting a tuple is greater than
or equal to 10000. Else generate an error message with the text “salary should be
greater than or equal to 10000”
Query:
1. Write a procedure to find out the name of the employee having maximum salary.
DELIMITER $$
mysql> CREATE PROCEDURE GetMaxSalaryEmployee()
-> BEGIN
52
-> SELECT FNAME,LNAME,SALARY FROM EMPLOYEE WHERE
SALARY=(SELECT MAX(SALARY) FROM EMPLOYEE);
-> END $$
Query OK, 0 rows affected (0.01 sec)
DELIMITER ;
CALL GetMaxSalaryEmployee();
+-----------+-----------+------------+
| FNAME | LNAME | SALARY |
+-----------+-----------+------------+
| Rani | Patel | 62000 |
+-----------+----------+------------+
1 row in set (0.00 sec)
2. Write a procedure to accept the department no and print the details of its
manager.
mysql> DELIMITER //
mysql> CREATE PROCEDURE GetManagerDetailsByDept(IN dept_no INT)
-> BEGIN
-> SELECT E.FNAME,E.LNAME,E.SSN,E.SALARY,E.ADDRESS FROM
EMPLOYEE AS E JOIN DEPARTMENT AS D ON E.SSN=D.MGRSSN
-> WHERE D.DNUMBER=dept_no;
-> END //
Query OK, 0 rows affected (0.00 sec)
mysql> DELIMITER ;
CALL GetManagerDetailsByDept(4);
+-----------+-----------+--------------+-------------+---------------------+
| FNAME | LNAME | SSN | SALARY | ADDRESS |
+-----------+-----------+--------------+-------------+---------------------+
| Rani | Patel | 555555555 | 62000 | T Nagar, Chennai |
+-----------+-----------+--------------+------------+-----------------------+
53
1 row in set (0.00 sec)
DELIMITER //
mysql> CREATE FUNCTION GETEMPDETAILS(PROJ INT)
-> RETURNS VARCHAR(255) DETERMINISTIC
-> BEGIN
-> DECLARE RESULT VARCHAR(255);
-> SELECT GROUP_CONCAT(E.FNAME,E.LNAME ORDER BY E.FNAME
SEPARATOR '\n')
-> INTO
-> RESULT FROM EMPLOYEE AS E,WORKS_ON AS W WHERE
E.SSN=W.ESSN AND PNO=PROJ;
-> RETURN RESULT;
-> END //
Query OK, 0 rows affected (0.00 sec)
SELECT GETPROJEMPDETAIL(1);
+----------------------------------------+
| GETPROJEMPDETAIL(1) |
+----------------------------------------+
| AnitaVerma,JohnDoe,SanjayRaj |
+---------------------------------------+
54
-> END //
Query OK, 0 rows affected (0.01 sec)
4. Create a procedure to give Rs.1000 hike in the salary of all the employees who
work in Research department. Update the table accordingly.
DELIMITER //
mysql> CREATE PROCEDURE UPDATESALARY()
-> BEGIN
-> UPDATE EMPLOYEE AS E JOIN DEPARTMENT AS D ON
E.DNO=D.DNUMBER SET SALARY=SALARY+1000 WHERE
DNAME="Research";
-> END //
Query OK, 0 rows affected (0.00 sec)
DELIMITER ;
mysql> SELECT SSN,SALARY FROM EMPLOYEE,DEPARTMENT WHERE
DNO=DNUMBER and DNAME="Research";
55
+------------+------------+
| SSN | SALARY |
+------------+------------+
| 111111111 | 50000 |
+-------------+-----------+
1 row in set (0.00 sec)
5. Create a trigger to update the total salary of a department when a new employee
is hired.
56
Rows matched: 4 Changed: 4 Warnings: 0
mysql> DELIMITER //
mysql> CREATE TRIGGER UpdateTotalSalary
-> AFTER INSERT ON EMPLOYEE
-> FOR EACH ROW
-> BEGIN
-> UPDATE DEPARTMENT SET
TOTAL_SALARY=TOTAL_SALARY+NEW.SALARY
-> WHERE DNUMBER=NEW.DNO;
-> END //
Query OK, 0 rows affected (0.01 sec)
mysql> DELIMITER ;
mysql> INSERT INTO EMPLOYEE
VALUES("Aarav","K","Patel",999999999,"1995-07-10","MG
Road,Bangalore","M",60000,NULL,2);
Query OK, 1 row affected (0.01 sec)
57
mysql> SELECT * FROM DEPARTMENT;
+-------------------+---------------+----------------+-------------------- --+-----------------------+
| DNAME | DNUMBER | MGRSSN | MGRSTARTDATE | TOTAL_SALARY |
+-------------------+---------------+---------------+------------------------+-----------------------+
| Research | 1 | 111111111 | 2010-01-01 | 51000 |
| Administration | 2 | 444444444 | 2011-02-15 | 167000 |
| IT | 4 | 555555555 | 2013-04-20 | 62000 |
| HR | 5 | 666666666 | 2014-05-25 | 95000 |
+------------------+----------------+----------------+------------------------+----------------------+
4 rows in set (0.00 sec)
6. The company has a policy that the minimum salary for an employee is 10000.
Create a trigger to check if the salary entered while inserting a tuple is greater
than or equal to 10000. Else generate an error message with the text “salary
should be greater than or equal to 10000”
DELIMITER ;
mysql> INSERT INTO EMPLOYEE
VALUES("Aarav","M","Singh",222222222,"1995-07-10","MG
Road,Bangalore","M",9000,NULL,1);
ERROR 1644 (45000): SALARY SHOULD BE GRATER THAN OR EQUAL TO
10000!
58
mysql> INSERT INTO EMPLOYEE
VALUES("Aarav","M","Singh",222222222,"1995-07-10","MG
Road,Bangalore","M",49000,NULL,1);
Query OK, 1 row affected (0.00 sec)
Result:
SQL Procedures and Functions have been executed.
59
Experiment No:11 Date:14/10/24
MongoDB Queries
AIM
Familiarization of NoSQL Databases and CRUD operations.
Query:
1. Add a new field ‘count’ whose value is 10 to the document where the item =
“journal”.
db.inventory.update(
{ item: "journal" },
{ $set: { count: 10 } }
)
60
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
db.inventory.find({})
{
"_id" : ObjectId("6560ace2e441817748969bc2"),
"item" : "journal",
"qty" : 25,
"size" : { "h" : 14, "w" : 21, "uom" : "cm" },
"status" : "A",
"count" : 10
}
{
"_id" : ObjectId("6560ace2e441817748969bc3"),
"item" : "notebook",
"qty" : 50,
"size" : { "h" : 8.5, "w" : 11, "uom" : "in" },
"status" : "A"
}
{
"_id" : ObjectId("6560ace2e441817748969bc4"),
"item" : "paper",
"qty" : 100,
"size" : { "h" : 8.5, "w" : 11, "uom" : "in" },
"status" : "D"
}
{
"_id" : ObjectId("6560ace2e441817748969bc5"),
"item" : "planner",
"qty" : 75,
"size" : { "h" : 22.85, "w" : 30, "uom" : "cm" },
"status" : "D"
}
{
"_id" : ObjectId("6560ace2e441817748969bc6"),
"item" : "postcard",
61
"qty" : 45,
"size" : { "h" : 10, "w" : 15.25, "uom" : "cm" },
"status" : "A"
}
db.inventory.update(
{ item: "notebook" },
{ $inc: { qty: 10 } }
)
db.inventory.find({})
{
"_id" : ObjectId("6560ace2e441817748969bc2"),
"item" : "journal",
"qty" : 25,
"size" : { "h" : 14, "w" : 21, "uom" : "cm" },
"status" : "A",
"count" : 10
}
{
"_id" : ObjectId("6560ace2e441817748969bc3"),
"item" : "notebook",
"qty" : 60,
"size" : { "h" : 8.5, "w" : 11, "uom" : "in" },
"status" : "A"
}
{
"_id" : ObjectId("6560ace2e441817748969bc4"),
"item" : "paper",
"qty" : 100,
"size" : { "h" : 8.5, "w" : 11, "uom" : "in" },
"status" : "D"
62
}
{
"_id" : ObjectId("6560ace2e441817748969bc5"),
"item" : "planner",
"qty" : 75,
"size" : { "h" : 22.85, "w" : 30, "uom" : "cm" },
"status" : "D"
}
{
"_id" : ObjectId("6560ace2e441817748969bc6"),
"item" : "postcard",
"qty" : 45,
"size" : { "h" : 10, "w" : 15.25, "uom" : "cm" },
"status" : "A"
}
3. For the third document , decrement the quantity by 15 and set status to “C”.
db.inventory.updateOne(
{ item: "paper" },
{ $inc: { qty: -15 }, $set: { status: "C" } }
)
db.inventory.find({})
{
"_id" : ObjectId("6560ace2e441817748969bc2"),
"item" : "journal",
"qty" : 25,
"size" : { "h" : 14, "w" : 21, "uom" : "cm" },
"status" : "A",
"count" : 10
}
{
"_id" : ObjectId("6560ace2e441817748969bc3"),
63
"item" : "notebook",
"qty" : 60,
"size" : { "h" : 8.5, "w" : 11, "uom" : "in" },
"status" : "A"
}
{
"_id" : ObjectId("6560ace2e441817748969bc4"),
"item" : "paper",
"qty" : 85,
"size" : { "h" : 8.5, "w" : 11, "uom" : "in" },
"status" : "C"
}
{
"_id" : ObjectId("6560ace2e441817748969bc5"),
"item" : "planner",
"qty" : 75,
"size" : { "h" : 22.85, "w" : 30, "uom" : "cm" },
"status" : "D"
}
{
"_id" : ObjectId("6560ace2e441817748969bc6"),
"item" : "postcard",
"qty" : 45,
"size" : { "h" : 10, "w" : 15.25, "uom" : "cm" },
"status" : "A"
}
db.inventory.updateOne(
{ item: "paper" },
{ $unset: { size: "" } }
)
db.inventory.find({})
64
{
"_id" : ObjectId("6560ace2e441817748969bc2"),
"item" : "journal",
"qty" : 25,
"size" : { "h" : 14, "w" : 21, "uom" : "cm" },
"status" : "A",
"count" : 10
}
{
"_id" : ObjectId("6560ace2e441817748969bc3"),
"item" : "notebook",
"qty" : 60,
"size" : { "h" : 8.5, "w" : 11, "uom" : "in" },
"status" : "A"
}
{
"_id" : ObjectId("6560ace2e441817748969bc4"),
"item" : "paper",
"qty" : 85,
"status" : "C"
}
{
"_id" : ObjectId("6560ace2e441817748969bc5"),
"item" : "planner",
"qty" : 75,
"size" : { "h" : 22.85, "w" : 30, "uom" : "cm" },
"status" : "D"
}
{
"_id" : ObjectId("6560ace2e441817748969bc6"),
"item" : "postcard",
"qty" : 45,
"size" : { "h" : 10, "w" : 15.25, "uom" : "cm" },
"status" : "A"
}
65
5. Delete the documents where status = “A”.
WriteResult({ "nRemoved" : 3 })
db.inventory.find({})
{
"_id" : ObjectId("6560ace2e441817748969bc4"),
"item" : "paper",
"qty" : 85,
"status" : "C"
}
{
"_id" : ObjectId("6560ace2e441817748969bc5"),
"item" : "planner",
"qty" : 75,
"size" : { "h" : 22.85, "w" : 30, "uom" : "cm" },
"status" : "D"
}
> db.inventory.count()
2
> db.inventory.drop()
True
db.dropDatabase()
66
{ "dropped" : "mydb_57", "ok" : 1 }
show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
mydb 0.000GB
Result:
NoSQL Database has been created and CRUD operations are executed .
67
Experiment No:12 Date:4/11/24
DBMS PROJECT
Aim:
The aim of this project is to design and implement a comprehensive railway management
system that manages railway operations efficiently, enhances passenger experience, and
secures ticketing processes.
Objective:
This project aims to create a digital platform for railway booking, passenger
management, and scheduling, reducing manual intervention and making railway services
more accessible to users.
Introduction:
Railways serve as a backbone for mass transportation. Managing such a system requires a
structured platform that simplifies ticket booking, passenger management, and
scheduling. This project focuses on developing a railway management system with
essential features like user login, signup, and train schedule viewing, enabling users to
access information and services conveniently.
Software Used:
● Frontend: A user-friendly interface with login and signup options, pages for train
schedule viewing, ticket booking, a streamlined booking process and cancel
tickets.
68
● Backend: A robust relational database to store user data, ticket information, and
train schedules. Database relations, such as foreign keys, maintain data
consistency and integrity.
Methodology:
SCREENSHOTS:
DATABSE CONNECTION:
69
Homepage:
70
Booking Pages:
71
Train Schedule:
72
Cancel Ticket:
Database:
railway_system:
user(username, password, email, mobile_number, gender, age, name)
train(train_no, train_name, seat_avail, class)
passanger(pno, p_name, p_age, p_gender, seat_no, ticket_no)
station(station_no, source, destination, fare, arrival_time, depart_time, duration, train_no)
ticket(ticket_no, status, date, phno, email, train_no, station_no, username)
73
● station.train_no references train(train_no) with ON DELETE CASCADE.
● ticket.train_no references train(train_no).
● ticket.station_no references station(station_no).
● ticket.username references user(username) with ON DELETE CASCADE.
Conclusion:
The Railway Management System database project offers an effective solution for
managing railway operations by integrating user accounts, train schedules, ticketing, and
passenger details into a cohesive relational database. This structure ensures data integrity and
improves user experience, facilitating seamless interactions for user registration, ticket booking,
and train scheduling. Overall, the project provides a solid foundation for a scalable and efficient
railway management system, ready to adapt to future needs and enhancements.
Result:
Database connectivity have been performed.
74