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

Dbms Record 2021 Even

Uploaded by

Yogesh 02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Dbms Record 2021 Even

Uploaded by

Yogesh 02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 40

DHANALAKSHMI SRINIVASAN

COLLEGE OF ENGINEERING
Coimbatore-641 105
[Approved by AICTE, New Delhi || Affiliated to Anna University, Chennai]

RECORD NOTE BOOK


DHANALAKSHMI SRINIVASAN
COLLEGE OF ENGINEERING
Coimbatore-641 105
[Approved by AICTE, New Delhi || Affiliated to Anna University, Chennai]

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

[CS3481-DATABASE MANAGEMENT SYSTEMS LABORATORY]


FOURTH SEMESTER

DHANALAKSHMI SRINIVASAN COLLEGE OF


ENGINEERING COIMBATORE-641105
3

LIST OF EXPERIMENTS:

1. Create a database table, add constraints (primary key, unique, check, Not null), insert rows, update and
delete rows using SQL DDL and DML commands.

2. Create a set of tables, add foreign key constraints and incorporate referential integrity.

3. Query the database tables using different ‘where’ clause conditions and also implement aggregate
functions.

4. Query the database tables and explore sub queries and simple join operations.

5. Query the database tables and explore natural, equi and outer joins.

6. Write user defined functions and stored procedures in SQL.

7. Execute complex transactions and realize DCL and TCL commands.

8. Write SQL Triggers for insert, delete, and update operations in a database table.

9. Create View and index for database tables with a large number of records.

10. Create an XML database and validate it using XML schema.

11. Create Document, column and graph based data using NOSQL database tools.

12. Develop a simple GUI based database application and incorporate all the abovementioned features

13. Case Study using any of the real life database applications from the following list.

PREPARED BY

Mrs.R.Ramya/AP
4

EXP NO: 1 CREATE A DATABASE TABLE, ADD


CONSTRAINTS (PRIMARY KEY, UNIQUE, CHECK,
NOT NULL), INSERT ROWS, UPDATE AND
DELETE ROWS USING SQL DDL AND DML
DATE: COMMANDS

AIM

To Create a database table, add constraints (primary key, unique, check, not null)
insert rows, update and delete rows using SQL DDL and DML commands.

ALGORITHM
Step 1: Creating a Database Table with Constraints.
Step 2: Inserting Rows into the Table.
Step 3: Updating Rows in the Table
Step 4: Deleting Rows from the Table
Step 5: Use select command to display the output.

PROGRAM
CREATE DATABASE
mydb; SHOW
DATABASES;
USE mydb;
CREATE TABLE
users( id INT
PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(50) NOT NULL,
email VARCHAR(50) CHECK (email LIKE '%@%.%')
);
INSERT INTO users (id, username, password, email)
VALUES (1, 'john_doe', 'password123','
[email protected]'),
5

(2, 'jane_doe', 'password456', '[email protected]'),


(3, 'bob_smith', 'password789', '[email protected]');
SELECT * FROM users;
UPDATE users SET password = 'new_password' WHERE username = 'john_doe';
SELECT * FROM users;
DELETE FROM users WHERE username = 'bob_smith';
SELECT * FROM users;

OUTPUT

id username password email

1 john_doe password123 john_doe@exampl


e.com

2 jane_doe password456 jane_doe@example


.com

3 bob_smith password789 bob_smith@examp


le.com

id username password email

1 john_doe new_password john_doe@exampl


e.com

2 jane_doe password456 jane_doe@example


.com

3 bob_smith password789 bob_smith@examp


le.com

null null null nill

RESULT
Thus, to Create a database table, add constraints (primary key, unique, check, not
null), insert rows, update and delete rows using SQL DDL and DML commands is
successfully executed and verified.
6

EXP NO: 2 CREATE A SET OF TABLES, ADD FOREIGN


KEY CONSTRAINTS AND INCORPORATE
REFERENTIAL INTEGRITY

DATE:

AIM
To Create a set of tables, add foreign key constraints and incorporate referential
integrity.

ALGORITHM
Step 1: Determine the relationships between the tables.
Step 2: Create the tables, add primary keys and add foreign keys.
Step 3: Create the relationships.
Step 4: Enforce referential integrity, Test the database and incorporate referential integrity

PROGRAM
SHOW DATABASES;
USE mydatabase;
CREATE TABLE users2
(
user_id INT PRIMARY KEY,
username VARCHAR(50) NOT
NULL, email VARCHAR(50) NOT
NULL,
password VARCHAR(50) NOT NULL
);
CREATE TABLE posts1 (
post_id INT PRIMARY
KEY, user_id INT NOT
NULL,
title VARCHAR(100) NOT NULL,
content TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
7

FOREIGN KEY (user_id) REFERENCES users2(user_id) ON DELETE CASCADE


8

);
CREATE TABLE comments1 (
comment_id INT PRIMARY
KEY, user_id INT NOT NULL,
post_id INT NOT NULL,
content TEXT NOT
NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (post_id) REFERENCES posts1(post_id) ON DELETE CASCADE
);

INSERT INTO users2 VALUES


(1, 'john_doe', '[email protected]', 'password123');
INSERT INTO posts1 (post_id, user_id,title,content)
VALUES (1,1,'My First Post','This is the Content Of My First
Post.');
INSERT INTO comments1 (comment_id, user_id,post_id,content)
VALUES (1,1,1,'Great Post!');

SELECT * FROM users2;


SELECT * FROM posts1;
SELECT * FROM comments1;
DELETE FROM posts1 WHERE post_id = 1;
SELECT * FROM posts1;
9

OUTPUT

RESULT
Thus, to create a set of tables, add foreign key constraints and incorporate
referential integrity is successfully executed and verified.
10

EXP NO: 3 QUERY THE DATABASE TABLES USING


DIFFERENT ‘WHERE’ CLAUSE CONDITIONS
AND ALSO IMPLEMENT AGGREGATE
FUNCTIONS
DATE:

AIM

To query the database tables using different ‘where’ clause conditions and also
implement aggregate functions.

ALGORITHM
Step 1: Connect to the
database. Step 2: Select the
table.
Step 3: Specify the "where" clause conditions.
Step 4: Specify the aggregate function.
Step 5: Execute the SQL statement and retrieve the results.

PROGRAM
SHOW DATABASES;
use sys;
create table sales(
SalesID int primary key,
Product varchar(50) not null,
Date date not null,
Quantity int not null,
Price decimal(10,2) not null
);
insert into
sales(SalesID,Product,Date,Quantity,Price)
values(1,'Widget','2023-05-03',10,19.99);
insert into
sales(SalesID,Product,Date,Quantity,Price)
11

values(2,'Gizmo','2023-05-03',5,12.99);
12

insert into
sales(SalesID,Product,Date,Quantity,Price)
values(3,'Thing','2023-05-02',2,7.99);
insert into
sales(SalesID,Product,Date,Quantity,Price)
values(4,'Widget','2023-05-01',10,19.99);
select * from sales where Product = 'Widget';
select * from sales where Quantity >= 10;
select * from sales where Date = '2023-05-03';
select Product, COUNT(*) AS num_sales from sales group by Product;
select sum(Quantity * Price) as total_revenue, avg(Price) as avg_price from sales;
select sum(Quantity * Price) as total_revenue from sales where Product = 'Gizmo';
select max(Price) as max_price, min(Price) as min_price from sales;
select avg(Quantity) as avg_quantity from sales where date >= '2023-05-01';

OUTPUT

RESULT
Thus, to query the database tables using different ‘where’ clause conditions and also
implement aggregate functions is successfully executed and verified.
13

EXP NO: 4 QUERY THE DATABASE TABLES AND


EXPLORE SUB QUERIES AND SIMPLE
JOIN OPERATIONS.
DATE:

AIM
To query the database tables and explore sub queries and simple join operations.

ALGORITHM
Step 1: Connect to the database and select the database.
Step 2: Understand the database schema.
Step 3: Write a simple SELECT statement.
Step 4: Explore subqueries and use simple join operations.
Step 5: Refine your queries, Test and execute your queries.

PROGRAM
create table customers1(
customer_id int primary
key, first_name varchar(50),
last_name varchar(50),
email varchar(100),
country varchar(50)
);

insert into customers1 values


(1,'John','Doe','[email protected]','USA'),
(2,'Jane','Doe','[email protected]','Canada'),
(3,'Bob','Smith','[email protected]','USA'),
(4,'Alice','Johnson','[email protected]','Australia');
14

create table orders(


order_id int primary key,
order_date date,
total_amount decimal(10,2),
customer_id int,
foreign key (customer_id) references customers1(customer_id)
);

insert into orders (order_id,order_date,total_amount,customer_id)


values (1001,'2023-05-01',50.00,1),
(1002,'2023-05-02',75.00,2),
(1003,'2023-05-02',100.00,1),
(1004,'2023-05-03',25.00,4),
(1005,'2023-05-03',200.00,3);

SELECT * FROM customers1;


SELECT * FROM orders;

select order_id, customer_id,order_date,total_amount


from orders
where customer_id IN (
select customer_id from customers1
where country ='USA'
);

select customers1.customer_id, customers1.first_name, customers1.last_name,


orders.order_id,orders.order_date,orders.total_amount
from customers1
inner join orders
on customers1.customer_id = orders.customer_id;
15

select customers1.first_name,orders.order_date,orders.total_amount
from customers1
left join orders
on customers1.customer_id = orders.customer_id;

select customers1.first_name,orders.order_date,orders.total_amount
from customers1
right join orders
on customers1.customer_id = orders.customer_id;

OUTPUT
16

RESULT
Thus, to query the database tables and explore sub queries and simple join operations
is successfully executed and verified.
17

EXP NO: 5 QUERY THE DATABASE TABLES AND EXPLORE


NATURAL, EQUI AND OUTER JOINS.

DATE:

AIM

To query the database tables and explore natural, equi and outer joins.

ALGORITHM
Step 1: Connect to the database and choose a database.
Step 2: Choose a table.
Step 3: Write a SELECT statement.
Step 4: Explore natural joins, explore equi joins and explore outer joins.

PROGRAM
create table customers2(
customer_id int primary
key, name varchar(50),
city varchar(50)
);

create table orders1 (


order_id int primary
key, customer_id int,
city varchar(50),
amount decimal(10,2),
foreign key (customer_id) references customers2(customer_id)
);

insert into customers2 values(1,'Alice','London'), (2,'Bob','New York'), (3,'Charlie','Paris');


select * from customers2;
18

insert into orders1 (order_id,customer_id,city,amount) values


(1,1,’London’,100.00),
(2,2,’London’,200.00),
(3,1,’Paris’,150.00);

select * from
customers2 natural join
orders1;

select * from
customers2 join orders1
on customers2.customer_id=orders1.customer_id;

select * from
customers2 left outer
join orders1
on customers2.customer_id=orders1.customer_id;

select * from
customers2 right outer
join orders1
on customers2.customer_id=orders1.customer_id;
19

OUTPUT

RESULT
Thus, To Query the database tables and explore natural, equi and outer joins
is successfully executed and verified.
20

EXP NO: 6 WRITE USER DEFINED FUNCTIONS AND


STORED PROCEDURES IN SQL.

DATE:

AI
M
To write user defined functions and stored procedures in SQL.

ALGORITHM
Step 1: Create a user-defined
function. Step 2: Create a stored
procedure.
Step 3: Test your user-defined function and stored procedure.

PROGRAM
DELIMITER //
CREATE FUNCTION add_numbers1(num1 INT, num2
INT) RETURNS INT DETERMINISTIC BEGIN
DECLARE result INT; SET result =
num1+num2; RETURN result;
END//

SELECT add_numbers1(2,3);

create table customers(


customer_id int primary key,
customer_name varchar(50),
country varchar(50)
);
21

insert into customers values


(1,'John','USA'),
(2,'Jane','Canada'),
(3,'Bob','USA'),
(4,'Alice','Australia');

SELECT * FROM customers;

DELIMITER $$
CREATE PROCEDURE get_customer_by_country(IN country_name VARCHAR(50))
BEGIN
SELECT * FROM customers WHERE country = country_name;
END$$
CALL get_customer_by_country('USA');

OUTPUT

RESULT
Thus, To Write user defined functions and stored procedures in SQL is
successfully executed and verified.
22

EXP NO: 7 EXECUTE COMPLEX TRANSACTIONS AND


REALIZE DCL AND TCL COMMANDS.

DATE:

AI
M
To Execute complex transactions and realize DCL and TCL commands.

ALGORITHM
Step 1: Connect to the database.
Step 2: Define the transaction, begin the transaction and execute the
transaction. Step 3: Commit or rollback the transaction.
Step 4: Execute DCL and TCL commands.

PROGRAM
show databases;
use mysql;

create table employees(


id int auto_increment primary
key, first_name varchar(50) not
null, last_name varchar(50) not
null, email varchar(100) not null,
phone varchar(20),
hire_date date not null,
job_title varchar(50) not
null,
department varchar(50) not
null, salary decimal(10,2) not
null
);
23

insert into employees values


(1,"hasan","mustafa","[email protected]","HM","2023-05-05","Data Scientist","CSE",60000),
(2,"naveen","raj","[email protected]","NR","2023-05-04","Software Developer","CSE",55000),
(3,"nikhil","srinivasan","[email protected]","NS","2023-05-03","Web Developer","CSE",50000);

start transaction;
update employees set salary = 50000 where id = 3;
insert into employees values
(4,"John","Doe","[email protected]","JD","2023-05-05","Software Engineer","CSE",60000);
commit;
select * from employees;
grant select on employees to 'root'@'localhost';
revoke select on employees from 'root'@'localhost';

OUTPUT

Grant: 0 rows affected.


Revoke: 0 rows affected.

RESULT
Thus, To Execute complex transactions and realize DCL and TCL commands is
successfully executed and verified.
24

EXP NO: 8 WRITE SQL TRIGGERS FOR INSERT,


DELETE, AND UPDATE OPERATIONS IN A
DATABASE TABLE.
DATE:

AI
M
To Write SQL Triggers for insert, delete, and update operations in a database table.

ALGORITHM
Step 1: Decide on the trigger event and
timing. Step 2: Choose the table.
Step 3: Determine the action
Step 4: Create the trigger and write the trigger actions.
Step 5: Test the trigger and modify the trigger as needed.

PROGRAM
create table users(
id int primary key not
null, age int
);

delimiter $$
create trigger insert_trigger1
after insert
on users
for each row
begin
insert into audit_table (inserted_id, inserted_data) values
(NEW.id,NEW.age); end;
25

delimiter $$
create trigger delete_trigger1
after delete
on users
for each row
begin
insert into audit_table (deleted_id, deleted_data) values (OLD.id,OLD.age);
end;

delimiter $$
create trigger update_trigger1
after update
on users
for each row begin
insert into audit_table (updated_id, old_data,new_data) values (NEW.id,OLD.age,NEW.age);
end;
26

OUTPUT

Insert Trigger:

create trigger insert_trigger1 after insert on 0 0.093


users for each row begin insert into row(s) sec
audit_table (inserted_id, inserted_data) affecte
values (NEW.id,NEW.age); end; d

Delete Trigger:

create trigger delete_trigger1 after delete 0 0.047


on users for each row begin insert into row(s) sec
audit_table (deleted_id, deleted_data) affecte
values (OLD.id,OLD.age); end; d

Update Trigger:

create trigger update_trigger1 after update 0 0.062


on users for each row begin insert into row(s) sec
audit_table (updated_id, affecte
old_data,new_data) values d
(NEW.id,OLD.age,NEW.age); end;

RESULT
Thus, to write SQL Triggers for insert, delete, and update operations in a database
table is successfully executed and verified.
27

EXP NO: 9 CREATE VIEW AND INDEX FOR DATABASE


TABLES WITH A LARGE NUMBER OF
RECORDS.
DATE:

AIM

To Create View and index for database tables with a large number of records.

ALGORITHM
Step 1: Create a table and insert values into it.
Step 2: Create a view.
Step 3: Create an index.
Step 4: Use select statement to display the result.

PROGRAM
create table orders5(
order_id int primary key,
customer_id int not null,
order_date date not null,
order_total decimal(10,2) not null,
ship_address varchar(255),
ship_city varchar(50),
ship_country varchar(50)
);

insert into orders5 values


(1,123,'2023-05-04',50.00,'123 Main St','Anytown','USA'),
(2,456,'2023-05-05',75.00,'456 Elm St','Other town','Canada'),
(3,789,'2023-05-06',100.00,'123 Oak St','Another town','Mexico');
28

create view orders_by_country1 as


select order_id,customer_id,order_date,order_total,ship_address,ship_city,ship_country
from orders5
where ship_country ='USA';

create index my_index_name on orders5(customer_id);


select * from orders_by_country1;

OUTPUT

RESULT
Thus, to Create View and index for database tables with a large number of records is
successfully executed and verified.
29

EXP NO: 10 CREATE AN XML DATABASE AND VALIDATE


IT USING XML SCHEMA.

DATE:

AI
M
To Create an XML database and validate it using XML schema.

ALGORITHM
Step 1: Create the XML
database. Step 2: Save the XML
database. Step 3: Create the XSD
schema.
Step 4: Validate the XML database using XSD schema.
30

PROGRAM
XML Database:

<?xml version="1.0" encoding="UTF-8"?>


<library>
<book id="001">
<title>The Catcher in the Rye</title>
<author>J.D. Salinger</author>
<year>1951</year>
</book>
<book id="002">
<title>To Kill a Mockingbird</title>
<author>Harper Lee</author>
<year>1960</year>
</book>
<book id="003">
<title>1984</title>
<author>George Orwell</author>
<year>1949</year>
</book>
</library>

XSD schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>

<xs:element name="title" type="xs:string"/>


<xs:element name="author" type="xs:string"/>
<xs:element name="year" type="xs:gYear"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>
31

OUTPUT
The file is valid

RESULT
Thus, To Create an XML database and validate it using XML schema is successfully
executed and verified.
32

EXP NO: 11 CREATE DOCUMENT, COLUMN AND GRAPH-


BASED DATA USING NOSQL DATABASE

DATE:

AI
M
To Create Document, column and graph-based data using NOSQL database tools.

ALGORITHM
Step 1: Create document and insert it in mongodb documentation and execute
it. Step 2: Create column by using aggregation.
Step 3: Graph is visualised using visual tree.

PROGRAM
DOCUMENT:
{
"name": "John Doe",
"age": 35,
"email": "[email protected]",
"address": {
"street": "123 Main
St", "city":
"Anytown",
"state": "CA",
"zip": "12345"
}
}
COLUMN:
{
'name':1,
'age':1
}
33

OUTPUT
DOCUMENT:
_id: ObjectID('64561efc6ee99dd7cf4dfd04')
name: "John Doe",
age: 35,
email: "[email protected]",
address: Object
street: "123 Main St",
city: "Anytown",
state: "CA",
zip: "12345"

COLUMN:
_id:ObjectID('64561efc6ee99dd7cf4dfd
04') name:"John Doe",
age:35

GRAPH:
VISUAL TREE:
{
"stage": "COLLSCAN",
"nReturned": 1,
"executionTimeMillisEstimate": 0,
"works": 3,
"advanced": 1,
"needTime": 1,
"needYield": 0,
"saveState": 0,
"restoreState": 0,
"isEOF": 1,
"direction": "forward",
"docsExamined": 1
}

RESULT
Thus, To Create Document, column and graph-based data using NOSQL database
tools is successfully executed and verified.
34

EXP NO: 12 DEVELOP A SIMPLE GUI BASED DATABASE


APPLICATION AND INCORPORATE ALL
THE ABOVE-MENTIONED FEATURES
DATE:

AI
M
To Develop a simple GUI based database application and incorporate all the above-
mentioned features.

ALGORITHM
Step 1: Install required
packages. Step 2: Create a GUI.
Step 3: Connect to MySQL.
Step 4: Perform CRUD
operations. Step 5: Display data in
the GUI.

PROGRAM
SQL CODE
show databases;
use mysql;
CREATE TABLE customers (
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT
NULL, PRIMARY KEY (id)
);
select * from customers;
35

PYTHON CODE:
import tkinter as tk
import mysql.connector

# Connect to the MySQL database


mydb = mysql.connector.connect
(
host="127.0.0.1", user="root", password="hasan@123", database="mysql"
)

# Create a cursor object to execute SQL queries


mycursor = mydb.cursor()

# Create the main


window root = tk.Tk()
root.title("MySQL GUI")

# Create the labels and textboxes for the input fields


label1 = tk.Label(root, text="Name:")
label1.grid(row=0, column=0)
entry1 = tk.Entry(root)
entry1.grid(row=0, column=1)

label2 = tk.Label(root,
text="Age:") label2.grid(row=1,
column=0) entry2 = tk.Entry(root)
entry2.grid(row=1, column=1)
36

# Create a function to insert data into the database


def insert_data():
name =
entry1.get() age =
entry2.get()
sql = "INSERT INTO customers (name, email) VALUES (%s, %s)"
val = (name, age)
mycursor.execute(sql, val)
mydb.commit()
print(mycursor.rowcount, "record inserted.")

# Create a button to insert data into the database


button1 = tk.Button(root, text="Insert", command=insert_data)
button1.grid(row=2, column=1)

# Run the main event


loop root.mainloop()

OUTPUT

RESULT
Thus, To Develop a simple GUI based database application and incorporate all
the above-mentioned features is successfully executed and verified.
37

EXP NO: 13 CASE STUDY USING ANY OF THE REAL-LIFE


DATABASE APPLICATIONS FROM THE
FOLLOWING LIST.
A) INVENTORY MANAGEMENT FOR A
EMART GROCERY SHOP
DATE:

ER-DIAGRAM

+ +
| Suppliers |
+ +
| supplier_id (PK) |
| supplier_name |
| supplier_phone |
| supplier_email |
+ +
|
|
|
+---------------------+ +
| Inventory |
+---------------------+ +
| item_id (PK) | supplier_id (FK)|
| item_name | item_quantity |
| item_price | item_category |
| item_description| item_location |
+---------------------+ +
|
|
|
+---------------------+ +
| Orders |
+---------------------+ +
| order_id (PK) | customer_id (FK)|
| order_date | item_id (FK) |
| order_quantity | order_status |
| order_total | order_type |
+---------------------+ +
|
|
|
+ +
| Customers |
+ +
| customer_id (PK) |
| customer_name |
| customer_phone |
| customer_email |
+ +
38

Normalization Rules:

1. First Normal Form (1NF):


All table columns must have atomic values (i.e., no multivalued attributes or repeating
Each table must have a primary key that uniquely identifies each row. 2. Second Norm
Must satisfy the requirements of 1NF.
No partial dependencies (i.e., non-key attributes depend on part of the primary key).
3. Third Normal Form (3NF):
Must satisfy the requirements of 2NF.
No transitive dependencies (i.e., non-key attributes depend on other non-key attributes

Views:

● A view can be created to show the current stock levels for each item
in the inventory table.

Triggers:

● A trigger can be created to log all updates to the orders table for
auditing purposes.

Functions:

A function can be created to calculate the total value of all items in the inventory table

PL/SQL Stored Procedure:

A stored procedure can be created to calculate the EMI for a gold loan for each eligible cu
To showcase the ACID properties of the database, sample queries with appropriate setting

Atomicity: This property ensures that a transaction is treated as a single unit of work tha

Example query:
39

BEGIN TRANSACTION;

UPDATE Inventory SET item_quantity = item_quantity - 10 WHERE item_id = 1;

INSERT INTO Orders (customer_id, item_id, order_quantity, order_total, order_date,


order_status, order_type)

VALUES (1, 1, 10, 100, '2023-05-06', 'Processing',

'Online'); COMMIT;

Consistency: This property ensures that a transaction brings the database


from one valid state to another.

Example query:

BEGIN TRANSACTION;

UPDATE Inventory SET item_quantity = item_quantity - 10 WHERE item_id = 1;

INSERT INTO Orders (customer_id, item_id, order_quantity, order_total, order_date,


order_status, order_type)

VALUES (1, 1, 20, 200, '2023-05-06', 'Processing', 'Online');

COMMIT;

Isolation: This property ensures that transactions are executed in isolation


from each other, and concurrent transactions do not interfere with each
other.

Example query:

-- Session 1

BEGIN TRANSACTION;

UPDATE Inventory SET item_quantity = item_quantity - 10 WHERE item_id = 1;

-- Session 2

BEGIN TRANSACTION;
40

UPDATE Inventory SET item_quantity = item_quantity - 5 WHERE item_id = 1;

-- Session 1 COMMIT;
-- Session 2

COMMIT;

Durability: This property ensures that once a transaction is committed, it will remain so,

Example query:

-- Transaction is committed and data is written to disk BEGIN TRANSACTION;


UPDATE Inventory SET item_quantity = item_quantity - 10 WHERE item_id = 1;

INSERT INTO Orders (customer_id, item_id, order_quantity, order_total, order_date, or

VALUES (1, 1, 10, 100, '2023-05-06', 'Processing', 'Online'); COMMIT;


-- Power failure occurs

-- Upon system restart, the database will recover the committed transaction and ensure t

RESULT
Thus, case study of Inventory Management for a EMart Grocery Shop is
successfully done.

You might also like