0% found this document useful (0 votes)
27 views25 pages

Dbms Practicals

DBMS

Uploaded by

ATF Channel
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)
27 views25 pages

Dbms Practicals

DBMS

Uploaded by

ATF Channel
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/ 25

EXP 3

CREATE TABLE AND INSERT VALUE:


:~$ sudo mysql
[sudo] password for acpce:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.8.38-8ubuntu®.20.04.2 (Ubuntu)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.

oracle is a registered trademark of Oracle Corporation andfor its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database SECOMP;
Query OK, 1 row affected (8.38 sec)

mysql> use SECOMP;


Database changed
mysql> create table Doctor(Doctor_id int,DName varchar(3e), salary float);
Query OK, ® rows affected (8.90 sec)
mysql> insert into Doctor value (101, 'Harsh',b40000:
Query OK, 1 row affected (0.88 sec)

mysql> insert into Doctor value (162, 'Swapnil', 200000);


Query OK, 1 row affected (0.11 sec)

mysql> insert into Doctor value (104, 'Praneet', 3


Query OK, 1 row affected (08.41 sec)

mysql> insert into Doctor value (1 sahil’, 500000);


Query OK, 1 row affected (1.85 sec)

SELECT:

Terminal » Feb14 11:45

acpce@acpce-ThinkCentre-M70s: ~

Query OK, 1 row affected (1.85 sec)

mysql> select * from Doctor;


+e ETRE +
| Doctor_id |
+
| Harsh |
| Swapnil |
| Praneet |
|
+e-
4 rows

Swapnil |
Praneet |

select DName, Salary from Doctor;


cement
Salary |

4 rows in set
Activities (J Terminal+ Feb14 11:45 e

ES +l acpce@acpce-ThinkCentre-M70s: ~

| Doctor_id | DName | salary |


Hommes I +
101 | Harsh | 460080
104 | Praneet | 300000 |
106 | Sahil | 560000

ne
| Harsh
| Praneet
| sahil
3 rows in set (0.00 sec)

mysql> describe Doctor;

| poctor_id
| DName varchar(30) | YES
| salary
+ +
3 rows in set (0.01 sec)

mysql> use asd


Reading table information for completion of table and celumn names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> A
>;
ERROR 1064 (42008): You have an error in your SQL syntax; check the manual that correspends to your MySQL server version for the right syntax
to use near 'A' at line 1
mysql> exit]

ALTER TABLE:
es Feb28 12:34 &

«yy Mm acpce@acpce-ThinkCentre-M70s: ~

mysql> use SECOMP;


Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from Doctor;
select * from Doctor;
~C
mysql> select * from Doctor;

:
| 460008
| 260608
| 366608
| 560606
+
4 rows in set (0.00 sec)
C

mysql> describe Doctor;


+

| Doctor_id
| DName varchar(30) | YES
| salary
+
3 rows in set (0.01 sec)

mysql> ALTER TABLE Doctor


-> ADD EMAIL CHAR(100);
Query OK, © rows affected (0.47 sec)
Records: ® Duplicates: @ Warnings: ©
Activities Terminal » Feb28 12:34

ES +1 acpce@acpce-ThinkCentre-M70s: ~

mysql> describe Doctor;

| Doctor_id | NULL
| DName varchar(30) | YES | NULL
| Salary float | NULL
+= +
3 rows in set (0.01 sec)

mysql> ALTER TABLE Doctor


-> ADD EMAIL CHAR(1@0);
Query OK, © rows affected (0.47 sec)
Records: © Duplicates: © Warnings: ©

mysql> select * from Doctor;


+
|
+
| Harsh | 400000
| Swapnil | 200000
| Praneet | 300000
| | seeeee
+
4 rows in set (0.00 sec)

mysql> UPADTE Doctor


-> SET EMAIL='[email protected]';
ERROR 1064 (420008): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
to use near 'UPADTE Doctor
SET EMAIL='[email protected]'' at line 1
mysql> UPADTE Doctor
-> SET EMAIL='[email protected]
-> WHERE EMAIL = 101;
ERROR 1064 (42008): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
to use near 'UPADTE Doctor
SET EMAIL='[email protected]'
= 101" at line 1

Activities (3 Terminal + Feb28 12:34 ®

“Y fl acpce@acpce-ThinkCentre-M70s: ~

mysql> UPDATE Doctor SET EMAIL = '[email protected]' WHERE Doctor_id = 101;


Query OK, 1 row affected (0.07 sec)
Rows matched: 1 Changed: 1 Warnings: ©

mysql> select * from Doctor;

| 400000
| 200000
| 300000
| 500000
+
4 rows in set (0.00 sec)

mysql> UPDATE Doctor SET EMAIL = '[email protected]' WHERE Doctorid = 104;


Query OK, 1 row affected (1.10 sec)
Rows matched: 1 Changed: 1 Warnings: ©

| 400000 [email protected]
| 200000 NULL
| 300000 [email protected]
| 560000
+
4 rows in set (0.00 sec)

mysql> UPDATE Doctor SET Dname = 'Priyanshu' WHERE Doctor_id = 166;


Query OK, 1 row affected (0.10 sec)
Rows matched: 1 Changed: 1 Warnings: ©
mysql> select * from Doctor;
+
| Docter_id | DName |
+
| 101 | Harsh | 400000
| 102 | Swapnil | 200000
| 104 | Praneet | 300000
| 106 | sahil | 500000
+ +
4 rows in set (0.00 c
sec)

mysql> UPDATE Doctor SET Dname = 'Priyanshu' WHERE Docter_id = 166;


Query OK, 1 row affected (8.10 sec)
Rows matched: 1 Changed: 1 Warnings: ©

mysql> select * from Doctor;

+
| | 400000 harshi23ggmail.com
| | 200000 | NULL
| | 308000 [email protected]
| Priyanshu | 500000
+
4 rows in set (0.00 sec)

mysql> UPDATE Docter SET EMAIL = '[email protected]' WHERE Doctor_id = 186;


Query OK, 1 row affected (0.42 sec)
Rows matched: 1 Changed: 1 Warnings: @

| Doctor_id | DName Salary | EMAIL


+ +
101 | Harsh

DELETE:
Activities &] Terminal v Feb28 12:34 e

“9 Il acpce@acpee-ThinkCentre-M70s: ~

| Doctor_id Salary | EMAIL


+
| 400000 | [email protected]
| i 200000 | NULL
| 300000 | [email protected]
| 5080000 | NULL
+
4 rows in set (0.00 sec)

mysql> UPDATE Doctor SET EMAIL = '[email protected]' WHERE Doctor_id = 106;


Query OK, 1 row affected (0.42 sec)
Rows matched: 1 changed: 1 Warnings: ©

mysql> select * from Doctor;


H
salary | EMAIL
+
400000 | [email protected]
200000 | NULL
300000 | [email protected]
500000 | [email protected]
+
rows in set (0.01 sec)

mysql> DELETE FROM Doctor WHERE DName = 'Swapnil';


Query OK, 1 row affected (1.34 sec)

mysql> select * from Doctor;


IN
Salary

Harsh 400000 | [email protected]


Praneet 300000 | [email protected]
Priyanshu 500000 | [email protected]
+
3 rows in set (0.01 sec)

mysql> 0
RENAME TABLE :
Activities Terminal Feb 28 12:3

acpce@acpce-ThinkCentre-M70s: ~

EMAIL
+ + -
LETS 00000 harshi123g@gmail
0 Swapnil NULL
0 Praneet 300000 [email protected] |
06 Priyanshu | 500000 [email protected] |
--- - --+
rows in set

mysql> DELETE FROM Doctor WHERE DName = 'Swapnil';


Query OK, 1 row affected (1.34 sec)

select * from Doctor


SO + 3
PIELE) Salary EMAIL
+
101 | Harsh pe060 | harshi23@gmail
104 | Praneet POOOO | praneeti5@gmati
106 | Priyanshu | 500000 | [email protected]
doen Home ---
3 rows in set (0.01 sec)

mysql> ALTER TABLE Doctor RENAME DOCTOR;


Query OK, © rows affected (6.35 sec)

mysql> select * from DOCTOR;


4-- EE TEEEEE -
| poctor_id | DName EMAIL

Harsh 00000 harsh123g@gmail


| Praneet | 300000 [email protected]
| Priyanshu | 500000 [email protected]
FR -
3 rows in set (8
mysql> 0

DROP TABLE:

DName Salary | EMAIL

| | [email protected]
| Praneet 0ooe [email protected] |
| Priyanshu | 0OBO [email protected] |
Home + —-- +
3 rows in set (0.00 sec)

mysql> TRUNCATE TABLE DOCTOR;


Query OK, 0 rows affected (1.18 sec)
mysql> select * from DOCTOR;
Empty set (0.01 sec)

mysql> DROP TABLE DOCTOR;


Query OK, 0 rows affected (1.35 sec)
mysql> select * from DOCTOR;
ERROR 1146 (42502): Table 'SECOMP.DOCTOR' doesn't exist
TRUNCATE TABLE :

1 104 | Praneet | 300000 | [email protected] |

«
1 106 | Priyanshu | 500000 | [email protected] |
+ +n B = = o
4 in set (8.01 sec)

L] mysql> DELETE FROM Doctor WHERE DName


Query OK, 1 row affected (1.34 sec)
= 'Swapnil';

©
mysql> select * from Docto
-+- ---t +
|
“ +

B
101 | Harsh | 400000 | [email protected] |
104 | Praneet | 300000 [email protected] |
106 | Priyanshu | 500008 | [email protected] |
a +n --- --+

A
rows in set (0.01 sec)

mysql> ALTER TABLE Doctor RENAME DOCTOR;


Query OK, 0 rows affected (08.35 sec)

& mysql> select

DName 1

Harsh | 400000 | [email protected]


Praneet | 300000 | [email protected] |
Priyanshu | 500000 | [email protected] |
i MN

mysql> TRUNCATE TABLE DOCTOR;


Query OK, © rows affected (1.18 sec)

mysql> select * from DOCTOR;


Empty set (8.01 sec)

mysql> 0
Experiment no 4 : Integrity constraint

NOT NULL CONSTRAINT


CREATE TABLE College
(college_id INTEGER NOT NULL,
college name VARCHAR(20) NOT NULL,
college_address VARCHAR(20) NOT NULL,
college_ph_no INTEGER NOT NULL
);

FOREIGN KEY CONSTRAINT


CREATE TABLE Faculty
(faculty_name VARCHAR(20) NOT NULL,
faculty_qualification CHAR(20) NOT NULL,
faculty _subj_taught VARCHAR(20) NOT NULL,
faculty _experience INTEGER NOT NULL,
college_id INTEGER, FOREIGN KEY(college_id) REFERENCES College);

Result:
Number of Records: 2

faculty name Tacully gualification faculty subj laught facully experience collegeid

Kumar Sow ME Mechanics 10 532

Piyush Dagde MBBS Anatomy 8 246

CHECK CONSTRAINT

CREATE TABLE Faculty


(faculty_name VARCHAR(20) NOT NULL,
faculty_qualification CHAR(20) NOT NULL,
faculty _subj_taught VARCHAR(20) NOT NULL,
faculty experience INTEGER CHECK(faculty_experience>=5),
collegeid INTEGER, FOREIGN KEY(college_id) REFERENCES College);
PRIMARY KEY CONSTRAINT
CREATE TABLE Student
(student_ID INTEGER NOT NULL PRIMARY KEY,
student_name CHAR(50),
student_dob CHAR(8),
student_address VARCHAR(S5@)
)s

UNIQUE KEY CONSTRAINT


CREATE TABLE Department
(dept_name CHAR(20),
dept_hod CHAR(5@0) NOT NULL UNIQUE,
dept_no_students INTEGER,
dept_no_teachers INTEGER NOT NULL,
);
Experiment no 8 : views

SQL > CREATE VIEW CUSTOMERS_VIEW AS


SQL > SELECT * FROM CUSTOMERS_VIEW;
SELECT name, age
FROM CUSTOMERS;

| I |
| Khilan | |
| keushik | |
| Craiteli | 25 |
| Hardik | |
| Komal I |
| I |

SQL Updating a View

You can update a view by using the following syntax:

CREATE CR REPLACE VIEW view_name AS


SELECT ceclumnl, column2, ...
FROM table name
WHERE condition;

OUTPUT:

SQL > UPDATE CUSTOMERS_VIEW memes == Casi iTT ee -+


SET AGE = 35 | 10 | mAME | AGE | ADDRESS | SALARY |
WHERE name = 'Ramesh’';
EE brs mmn a EE td -

| 1 | Ramesh | 35 | Ahmedabad
| 2000.20 |
| 2 | %xnilan | 25 | Deni | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.08 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8see.ee |
| 6 | Xomal | 22 | wp | 4500.00 |
| 7 | Meffy | 24 | Indore | 10000.80 |
Ee EE BE -
SQL > DELETE FROM CUSTOMERS VIEW MERC es ee BR a srs i
WHERE age = 22; | ID | name | AGE | ADDRESS | SALARY |
Bt mmm EE EEE +

| 1] Ramesh | 35 | Ahmedabad | 2000.00 |


| 2 | knilan | 25 | Delni | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
Freep mmm Frm ———— Frm
mm ———— -

SQL Dropping a View


You can delete a view with the DROP VIEW command.
SQL DROP VIEW Syntax:

DRCP VIEW view name;

OUTPUT:
The table will be deleted.
Aim:-Perform simple queries,string manipulation operations and aggregate
functions.

Code:-
show databases;

create database employee;

use employes;

create table employee(eid int,ename varchar(25),ejob varchar(25),esal varchar(25));

insert into employee values(201,'Atharva’,'Engineer',100000);

insert into employee values(301,'Akash’,'Doctor',300000);

insert into employee values(401,'Ajay','Manager',150000);

insert into employee values(501,'Atharva','lAS',500000);

select * from employee;

alter table employee add primary key(eid);

alter table employee add unigque(ejob);

alter table employee alter ename set default "Unknown";

desc employee;

insert into employee values(222,'Roy','clerk’,150000);

insert into employee values(333,'Rahul','Accountant',200000);

insert into employee values(444,'Raj','Astronaut',500000);

select * from employee;

output:-

| Resuttarid | HH Fite
| rRov
||a:
export: BY | Wrap Cell Content: Ia
Database
» |employee
information_schema
mysal
performance_schema
sys
| Result Grid | HH FterRovs: [|| Exports ER | Wrap Cel Content: TA
| Field Type Null Key Default Extra
» |ed int NO PRI LOO
ename varchar(25) YES Unknown
ejob varchar(25) YES UNI ro
esal varchar(25) YES z=

| Result Grid | HH 43 FiterRows: | edi: 7) Eb BE | Export/tmport: ER 3 | Wrap cell Content: Ia

eid ename ejob esal


» |201 Atharva Engineer 100000
222 Roy derk 150000
301 Akash Doctor 300000
333 Rahul Accountant 200000
401 Ajay Manager 150000
444 Rj Astronaut 500000
501 Atharva IAS 500000
o [MY [my [my
1 row in set (8.82 sec)

vigly create table student rare varchar]


30), contact int, id int, dob date);
uiery OF, B rows affected (8.86 sec)

wogls insert into student wvalues( Manish", 5321528757


,85, 'Deeg-a5-84');
EFEOR 1364 (22080); Out of range value for column 'comtact’ at row 1
vigly create table student (rare veschar(3@), contact wvarchar(58),id ing, dob date);
ERROR 1858 (4X08): Tesla "student” alrasdy axists
rysgls> alter table sbudent update (contact wvarchar{58));
that corresponds to your MSIL server versio

Word have am arroe Ln pour SOL synta heck the manual corresponds to your MySQL server wersios
¥or the right syntax to use rear “set{contact varchar(S@))' at line 1
student {contact warchar(58)1;
You have an error in your SJL syntaw; check the manual corresponds £0 your MESQL server versio
Eprtax to use rear (contact varchac(S3))" at lire 1
Ble student medify caluen contact warchar[587;
ery CK, © rows affected {8.82 soc)
Records: © Duplicates: B Warnings: &

ryegls insert into student values('Mendeh’ 9021026757 05, "2002-06-04") ;


|: , 1 Pow Effected

ary OG, 1 rou affected (B.81 sec)

pgl> Eneert into student valoes( “Protest” BE2144 pT


1RRL 0-1
2, 1 row affected (9,81 sec)

wogl> select * from student)


+ v
| eantace id

88513756
Er el] 2o8di-82-15
JE I1491453 1000 -|E-15
input statement.
warchar (38),

wercha[#

Tinta sted values(2, “men


d (9.01 sec)

wagls fssert into stud w


1 rom affe
select * from st
DBMS EXPERIMENT NO: 8

SELECT * FROM student;


+

Parthivi | Kalamboli
Sagar | Kalyan
Yash K. | Panvel
Parth | Khandeshwar
Pragati | Kharghar
+

in set (©.00

mysql> SAVEPOINT a;
Query OK, © rows affected (0.00 sec)

mysql> UPDATE student SET Address= "Kharghar" WHERE Name= "Pragati";


Query OK, 1 row affected (0.80 sec)
Rows matched: 1 Changed: 1 Warnings: ©

mysql> ROLLBACK TO a;
Query OK, © rows affected (0.00 sec)

mysql> SELECT * FROM student;


+ — 4

Kalamboli
Kalyan
Panvel
——

(GELS ET
Nashik

mysql> INSERT INTO student (ID, Name, Address, Dept)


-> VALUES (NULL, "Vaishnavi", "Ghansoli", "C0");
Query OK, 1 row affected (@.01 sec)

mysql> COMMIT;
Query OK, 8 rows affected (0.01 sec)
mysql> ROLLBACK TO a;
ERROR 1365 (42000): SAVEPOINT a does not exist
mysql> select * from student;
+

-+

Parthivi Kalamboli |
Sagar Kalyan |
Yash K. Panvel |
Parth Khandeshwar |
Pragati Nashik |
Arya Nerul |
Vaishnavi | Ghansoli |
+
in set (9.60 sec)

mysql> CREATE USER 'dbms'@'localhost’ IDENTIFIED BY ‘abcd’;


Query OK, © rows affected (0.03 sec)

mysql> GRANT SELECT, INSERT ON *aids* TO 'dbms'@'localhost® WITH GRANT OPTION;


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual tha

mysql>
mysql> GRANT SELECT, INSERT ON *aids* TO 'dbms'@"localhost’;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual tha
mysql>
mysql> GRANT SELECT, INSERT ON aids TO 'dbms'@'localhost’;
ERROR 1146 (42502): Table 'aids.aids' doesn't exist
mysql> GRANT SELECT, INSERT ON dml.aids TO ‘dbms'@'localhost’;
ERROR 1146 (42502): Table 'dml.aids®' doesn't exist
mysql> GRANT SELECT, INSERT ON aids.dml TO ‘dbms'@'localhost’;
Query OK, © rows affected (0.91 sec)

mysql> REVOKE INSERT ON aids.student FROM dbms@localhost;


Query OK, © rows affected (8.01 sec)

mysql>
DBMS EXPERIMENT NO:9

Procedure:

mB ¥FFa [23] Lirnit to 1000 rows =

1e use customer;

ze select * from student;


3

| Result Grid | HH 4% Filter Rows: Export: EH] | irra Cell Con

studentID first_name Last_name age


Pl Sagar Chavan 19
z Wash Kahste 20
3 Parth Khatu 20
4 Atharva Thakur 22

The narne of the routine is parsed automatically fran the DOL


Mame: gef_student_info statement, The DDL iz parsed autamnatically while you type.

Emel
e l=
1e CREATE DEFIMER="root
ff localhost” PROCEDURE "get student info” (in age int)
.
2 BEGIN

3 select * from student where student.age=age;


4 END

get_student_info - Routing

BE FTFAQCD Lirnit bo 1000 rows ©

1e use customer;

28 select * from student;


3 e call get_student_info(20) ;

| Result Grid | TH Fier Ross: | Expert: Ei | wirap Call Canter:


studentID first_name Last_name age
PZ ‘ash Kahste 20
3 Parth Khatu 20
Functions:

Built-In Function:
IE get_student_info - Routine

EE ¥FFAO BR Limitto1000r0ws + |J |2 QQ (1)


le use customer;

ze select ¥ from student;


3 e select concat(first_name,” “,Last_rname) as full name from student;

| Result Grid | HB 4% Filter Rows: | Export: Em) [wir zp Cell Content: TA

full _narme
p |Sagar Chavan
‘ash Kahste
Parth kKhatu
Atharva Thakur

User-Defined Function:
get_student_infa - Routine add five - Routine thl Update - Routing

mE FFA ff Ltt 10000ws ~ |3 |9 @ [0 [3


LJ] use customer;

Ld CREATE TRBLE students (Mame WRRCHAR(L2®), Math INT, English INT, Science INT, History INT);
om

INSERT INTO students walues('Raman®, 95, &9, 85, 81);


fw

INSERT INTO students values('Rahul® , 9@, 87, 86, #1);

INSERT INTO students values('Mehit®, 2@, 85, 86, 81);


[]
mow

INSERT INTO students values('Saurabh®, MULL, MULL, MULL, MULL };


. select * from students;
ow
Woo

| Result Grid | HE 4% Filter Rows: Exports Cg | wirsp Call Content: TE


Mame Math English Science History
» Raman 95 a9 a5 81
Rahul an a7 86 81
Mohit El) 85 i) 81
Saurabh
nfo - Routing add_five - Aouting

tbl_Update

EEea [Rx
1 ® ATE DEFINER="
root @ localhost” FUNCTION "tbl_Updste™ (5_name Varchar(52), Ml INT, M2 INT, M3 INT, M4 INT) RETURNS int
2 DETERMINISTIC
3 iN
4 UPDATE students SET Math = ML, English = H2, Science = M3, History = M4
H WHERE Mame = 5_name; ‘
& RETURN 1;

7 END

add_five - Routine

ME ¥ FAQ R © OIMR umnom


1® Select thl_update( Saurabh”, 85,69, 75,82);
ze select ¥ from students;
3
4
.

| Result Grid | HB 4) Filer Rows: | Export: =]

Mame Math English Science History


# |FRaman a5 9 85 1
Rahul ag a7 gE gl
Mohit ag 85 faa] g1
Saurabh 85 69 7 82
DBMS PR 12 Code and Output

Code:

<?php

$servername = "localhost”;

$username = "id20578810_root™;

$password = "5%>+8omPMmN4)a|~";
$mydb = "id20578810_student”;

/I Create connection

$conn = mysqli_connect($servername, $username, $password, $mydb);

/I Check connection

if (1$conn) {

die("Connection failed: " . mysqli_connect_error());

}
// Start transaction

mysqli_autocommit($conn, FALSE);

/I' Acquire lock

mysqli_query($conn, "LOCK TABLES mytable WRITE");

// Update row with id = 1

$sql = "UPDATE mytable SET quantity = quantity - | WHERE id = 1";

if (mysqli_query($conn, $sql)) {

// Introduce artificial delay to simulate concurrency

sleep(5);

/l Try to update the same row concurrently

$sql2 = "UPDATE mytable SET quantity = quantity - 1 WHERE id = 1";

if (mysqli_query($conn, $sql2)) {

// Commit transaction

mysqli_commit($conn);

echo "Transaction committed.”;

} else {

// Rollback transaction on error

mysqli_rollback($conn);

1|DBMS-PR-12
echo "Transaction rolled back.”;

}
} else {

// Rollback transaction on error

mysqli_rollback($conn);

echo "Transaction rolled back.”;

}
// Release lock

mysqli_query($conn, "UNLOCK TABLES");

/I Close connection

mysqli_close($conny;

>

Output:

Transaction rolled back.

2|DBMS-PR-12

You might also like