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

Cs3481-Dbms Lab Manual

The document is a laboratory manual for the Database Management Systems course (CS3481) for II B.Tech CSBS students. It outlines a series of experiments that involve creating and manipulating database tables using SQL commands, including tasks like adding constraints, querying with various conditions, and implementing user-defined functions. Additionally, it covers advanced topics such as executing transactions, writing triggers, and working with NoSQL databases.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Cs3481-Dbms Lab Manual

The document is a laboratory manual for the Database Management Systems course (CS3481) for II B.Tech CSBS students. It outlines a series of experiments that involve creating and manipulating database tables using SQL commands, including tasks like adding constraints, querying with various conditions, and implementing user-defined functions. Additionally, it covers advanced topics such as executing transactions, writing triggers, and working with NoSQL databases.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS

LABORATORY MANUAL

COURSE CODE : CS3481

COURSE NAME : DATABASE MANAGEMENT SYSTEMS LABORATORY

REGULATION : R2021

CLASS & SEM : II B.TECH CSBS

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY

1
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 above-
mentioned features
13. Case Study using any of the real life database applications from the following list
a) Inventory Management for a EMart Grocery Shop
b) Society Financial Management
c) Cop Friendly App – Eseva
d) Property Management – eMall
e) Star Small and Medium Banking and Finance
 Build Entity Model diagram. The diagram should align with the business and
functional goals stated in the application.
 Apply Normalization rules in designing the tables in scope.
 Prepared applicable views, triggers (for auditing purposes), functions for enabling
enterprise grade features.
 Build PL SQL / Stored Procedures for Complex Functionalities, ex EOD Batch Processing
for calculating the EMI for Gold Loan for each eligible Customer.
● Ability to showcase ACID Properties with sample queries with
appropriate settings

2
CREATE A DATABASE TABLE, ADD CONSTRAINTS (PRIMARY
EXP NO: 1 KEY, UNIQUE, CHECK, NOT NULL), INSERT ROWS, UPDATE
AND DELETE ROWS USING SQL DDL AND DML 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]'), (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;

3
OUTPUT:

id Username password email

john_doe@exampl
1 john_doe password123
e.com

jane_doe@example
2 jane_doe password456
.com

bob_smith@examp
3 bob_smith password789
le.com

id Username password email

john_doe@exampl
1 john_doe new_password
e.com

jane_doe@example
2 jane_doe password456
.com

bob_smith@examp
3 bob_smith password789
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.

4
CREATE A SET OF TABLES, ADD FOREIGN KEY
EXP NO: 2 CONSTRAINTS AND INCORPORATE REFERENTIAL
INTEGRITY

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, FOREIGN KEY (user_id) REFERENCES users2(user_id) ON DELETE
CASCADE );

CREATE TABLE comments1 ( omment_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;

5
OUTPUT:

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

6
QUERY THE DATABASE TABLES USING DIFFERENT
EXP NO: 3 ‘WHERE’ CLAUSE CONDITIONS AND ALSO IMPLEMENT
AGGREGATE FUNCTIONS

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) values(2,'Gizmo','2023-05-


03',5,12.99);

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';

7
OUTPUT:

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

8
QUERY THE DATABASE TABLES AND EXPLORE SUB
EXP NO: 4
QUERIES AND SIMPLE JOIN OPERATIONS.

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'));

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;

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;

9
OUTPUT:

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

10
QUERY THE DATABASE TABLES AND EXPLORE NATURAL,
EXP NO: 5
EQUI AND OUTER JOINS

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;

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;

11
OUTPUT

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

12
WRITE USER DEFINED FUNCTIONS AND STORED
EXP NO: 6 PROCEDURES IN SQL

AIM:

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));

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');

13
OUTPUT:

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

14
EXECUTE COMPLEX TRANSACTIONS AND REALIZE DCL AND
EXP NO: 7
TCL COMMANDS

AIM:

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 );

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';

15
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.

16
WRITE SQL TRIGGERS FOR INSERT, DELETE, AND UPDATE
EXP NO: 8 OPERATIONS IN A DATABASE TABLE

AIM:

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;

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;

17
OUTPUT:

Insert
Trigger: create trigger insert_trigger1 after insert on 0 0.093
users for each row begin insert into audit_table row(s) sec
(inserted_id, inserted_data) values affecte
(NEW.id,NEW.age); end; d

Delete Trigger:

create trigger delete_trigger1 after delete on 0 0.047


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

Update Trigger:

create trigger update_trigger1 after update on 0 0.062


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

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

18
CREATE VIEW AND INDEX FOR DATABASE TABLES WITH A
EXP NO: 9
LARGE NUMBER OF RECORDS

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');

CREATE VIEW orders_by_country1 as select order_id, customer_id, order_date, order_total,


ship_address, ship_city, ship_country from orders 5 where ship_country ='USA';

CREATE INDEX my_index_name on orders5(customer_id);

SELECT * from orders_by_country1;

19
OUTPUT:

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

20
CREATE AN XML DATABASE AND VALIDATE IT USING XML
EXP NO: 10
SCHEMA

AIM:

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.

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>

21
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>

OUTPUT:

The file is valid

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

22
CREATE DOCUMENT, COLUMN AND GRAPH- BASED DATA
EXP NO: 11 USING NOSQL DATABASE

AIM:

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
}

23
OUTPUT:

DOCUMENT:
_id:
ObjectID('64561efc6ee99dd7cf4dfd
04') 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.

24
DEVELOP A SIMPLE GUI BASED DATABASE APPLICATION
EXP NO: 12 AND INCORPORATE ALL THE ABOVE-MENTIONED
FEATURES

AIM:

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;

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)

25
entry2.grid(row=1, column=1)

# 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()

26
OUTPUT:

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

27
CASE STUDY USING ANY OF THE REAL-LIFE DATABASE
APPLICATIONS FROM THE FOLLOWING LIST.
EXP NO: 13
A) INVENTORY MANAGEMENT FOR A EMART GROCERY
SHOP

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 |
+ +

28
Normalization Rules:
1. First Normal Form (1NF):
 All table column must have atomic value. (NO Multivalued Attribute / No
repeating group)
 Each table must have a primary key that uniquely identifies each row.
2. Second Normal Form (2NF):
 Must satisfy the requirement of 1NF.
 No Partial dependentices. (Non-key attribute depend on part of primary key
3. Third Normal Form (3NF):
 Must satisfy the requirement of 2NF.
 No transitive dependentices. (Non-key attribute depend on other non-key
attribute)
Views:
A view can be created to show the current stock level of 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 the 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 customer as part of end-of-day batch processing.
To showcase the ACID properties of the database, sample queries with appropriate settings
can be executed. ACID stands for Atomicity, Consistency, Isolation, and Durability, and these
properties ensure that transactions are processed reliably in a database system.
Atomicity: This property ensures that a transaction is treated as a single unit of work that
either completes in its entirety or not at all.
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, 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.
29
Example query:
-- Session 1
BEGIN TRANSACTION;
UPDATE Inventory SET item_quantity = item_quantity - 10 WHERE item_id = 1;
-- Session 2
BEGIN TRANSACTION;
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, even
in the face of power loss or other failures.
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, order_status,
order_type) 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 that
the data is consistent

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

30

You might also like