A LAB REPORT
ON
DATABASE MANAGEMENT SYSTEM
(Inventory Management System)
For the partial fulfillment of BIM 4th semester
Faculty of management
Shanker Dev Campus
Submitted by: Submitted to:
10386/19: Ujjwal Dhakal Anil Lamichhane
Database Management System
Contents
Introduction to Inventory Management System ...................................................................................... 4
Features.................................................................................................................................................... 4
Entity-Relation Model ................................................................................................................................ 5
Entity ........................................................................................................................................................ 5
Attributes ................................................................................................................................................. 6
Mapping Constraints .............................................................................................................................. 7
Introduction to SQL (Structured Query Language).............................................................................. 11
Data Definition Language (DDL) ........................................................................................................ 11
CREATE statement .......................................................................................................................... 11
ALTER statement ............................................................................................................................. 14
DROP statement................................................................................................................................ 14
Data Manipulation Language (DML) ................................................................................................. 15
INSERT statement ............................................................................................................................ 15
UPDATE statement .......................................................................................................................... 19
DELETE statement ........................................................................................................................... 20
SELECT, FROM & WHERE CLAUSE ............................................................................................. 21
AND operator ........................................................................................................................................ 21
OR operator........................................................................................................................................... 22
NOT operator ........................................................................................................................................ 22
ORDER BY CLAUSE ...................................................................................................................... 23
GROUP BY CLAUSE ...................................................................................................................... 23
HAVING CLAUSE ........................................................................................................................... 24
WILD CARD OPERATOR ................................................................................................................. 24
SQL FUNCTION .................................................................................................................................. 25
SQL JOIN .............................................................................................................................................. 27
INNER JOIN ..................................................................................................................................... 27
OUTER JOIN .................................................................................................................................... 28
ACKNOWLEDGEMENTS
Every organized report requires a lot of hard work and seeks a lot of helping hands.
This project has been an excellent opportunity for us to explore our knowledge and
implement skills we gained from our syllabus. The success and outcome of this
project required a lot of guidance and assistance from many people.
First of all, we would like to thank our subject teacher Anil Lamichhane for proper
guidance, encouragement and moderation during our classes. It would not have been
possible without the kind support and help of our subject teacher as well as Shanker
Dev Campus faculty. Also, we owe thank to our dear friends for their continuous
support and help on the completion of this report.
At last, I would like to thank every individual who have offered assistance,
encouragement, co-operation and helping hand for complete my report successfully.
Introduction to Inventory Management System
Normally people use the pen-paper method for record keeping which is quite un-easy,
uncomfortable and sometimes inaccurate. For overcoming this we came with a solution of
inventory management system. From this system, we can generate records for each and every
purchase. In addition to this, we can manage other details this system.
Inventory Management system provides information to efficiently manage the flow of materials,
coordinate management activities and communicate with customers. It helps with monitoring and
maintenance of stocked products, if they are available or not, details of those products. This
system can be used by normal shops, departmental stores for keeping a proper track of the stock.
It also consists of information like manager details, customer details etc.
Features:
Accuracy: - The level of accuracy in the proposed system will be higher. All operation would
be done correctly and it ensures that whatever information is coming from the center is accurate.
Reliability: - The reliability of the proposed system will be high due to the above stated reasons.
The reason for the increased reliability of the system is that now there would be proper storage of
information.
No Redundancy: - In the proposed system utmost care would be that no information is repeated
anywhere, in storage or otherwise. This would assure economic use of storage space and
consistency in the data stored.
Immediate retrieval of information: - The main objective of proposed system is to provide for
a quick and efficient retrieval of information.
Immediate storage of information: - In manual system there are many problems to store the
largest amount of information.
Easy to Operate: - The system should be easy to operate and should be such that it can be
developed within a short period of time and fit in the limited budget of the user.
Entity-Relation Model
Entity-Relationship (ER) Model is based on the notion of real-world entities and relationships
among them. While formulating real-world scenario into the database model, the ER Model creates
entity set, relationship set, general attributes and constraints.
ER Model is based on −
• Entities and their attributes.
• Relationships among entities.
An Entity Relationship (ER) Diagram is a type of flowchart that illustrates how “entities” such as
people, objects or concepts relate to each other within a system. ER Diagrams are most often used
to design or debug relational databases in the fields of software engineering, business information
systems, education and research.
Entity
An entity is a “thing” or “object” in the real world that is distinguishable from all
other objects. For example, each person in an enterprise is an entity. An entity has a
set of properties, and the values for some set of properties may uniquely identify an
entity. Inventory Management System has entities like customer, products, brands, etc.
Types of Entity:
1. Strong Entity Types
the entities which have a key attribute in its attribute
list or a set that has a primary key. The strong entity type is also called regular entity
type.
2. Weak Entity Types
Entity Type with no key or Primary Key are called weak entity Type.
The Tuples of weak entity type may not be possible to differentiate using one attribute
of weak entity.
3. Composite Entity Types or Associative Entity Types
Composite Entities are the entities which exist as a relationship as well as an
entity.
Attributes
Attributes are descriptive properties possessed by each member of an entity set.
The designation of an attribute for an entity set expresses that the database stores
similar information concerning each entity in the entity set; however, each entity
may have its own value for each attribute. Here, attributes of the customer entity
set are customer-id, customer-name, customer-street, and customer-city.
Attribute types.
Simple and composite attributes:
The attribute that is, they are not divided into subparts is simple attribute. Composite attributes
are those which can be divided into subparts (that is, other attributes).
Single-valued and multivalued attributes.
The attributes which have a single value for a particular entity are single valued attributes. The
attributes which have more than one value is said to be multivalued attributes.
Derived attribute.
An attribute which can be derived from other attributes of the entity type is called derived
attribute.
Null value:
An attribute takes a null value when an entity does not have a value for it.
Mapping Constraints
A mapping constraint is a data constraint that expresses the number of entities to which another
entity can be related via a relationship set.It is most useful in describing the relationship sets that
involve more than two entity sets.
For binary relationship set R on an entity set A and B, there are four possible mapping cardinalities.
These are as follows:
One-to-one
In one-to-one mapping, an entity in E1 is associated with at most one entity in E2, and an entity in
E2 is associated with at most one entity in E1.
One-to-many
In one-to-many mapping, an entity in E1 is associated with any number of entities in E2, and an
entity in E2 is associated with at most one entity in E1.
Many-to-one
In one-to-many mapping, an entity in E1 is associated with at most one entity in E2, and an entity
in E2 is associated with any number of entities in E1.
AD
Many-to-many
In many-to-many mapping, an entity in E1 is associated with any number of entities in E2, and an
entity in E2 is associated with any number of entities in E1.
ER diagram of Inventory management system
Entities & its Attributes
Inventory (userid, username, password, usertype)
Brand (brandid, brandname)
Categories (catid, catname)
Products (prodid, prodname, prodstock, prodprice)
Store (storeid, storename, address, storephone)
Cart (cartid, name, cphone)
Transactions (userid, discount, cartid )
Invoice (userid, username, prodname, prodprice, quantity)
Relations :
- Inventory (User) pays bills.
- Store provides products
- Products has brands
- Products has categories
- Products add to cart
- Cart transacts to bill
Introduction to SQL (Structured Query Language)
Data Definition Language (DDL)
Database language that is used to create, delete or modify database schema is called data
definition language. DDL is also used to define external schemas.
Domain Types in SQL
1. int or Integer
2. Character or char
3. Variable Character or Varchar
4. Datetime
5. Floating or float
6. Enumeration or enum
7. Decimal
Structured query language supports following DDL statements:
CREATE statement
Syntax:
CREATE DATABASE database_name;
CREATE TABLE Table_name;
Create database :
CREATE DATABASE Inventory;
Creating Tables :
CREATE TABLE Inventory(
userid INT PRIMARY KEY,
username CHAR(20) NOT NULL,
address VARCHAR(20),
contact INT(10)
);
CREATE TABLE Brands (
brandid int PRIMARY KEY,
brandname varchar(255)
);
CREATE TABLE Categories (
catid int PRIMARY KEY,
catname varchar(255)
);
CREATE TABLE Products (
prodid int PRIMARY KEY,
prodname varchar(255),
prodstock int,
prodprice float
);
CREATE TABLE Store (
storeid int PRIMARY KEY,
storename varchar(255),
storeaddress varchar(255) ,
storephone int
);
CREATE TABLE Cart (
cartid int PRIMARY KEY,
userid int,
FOREIGN KEY (userid) REFERENCES Inventory(userid)
);
CREATE TABLE Bill(
billcode int PRIMARY KEY,
userid int,
prodid int,
cartid int,
quantity int,
amount float,
FOREIGN KEY (userid) REFERENCES inventory(userid),
FOREIGN KEY (prodid) REFERENCES products(prodid),
FOREIGN KEY (cartid) REFERENCES cart(cartid)
);
ALTER statement
Alter command is used for alteration of table structure.
ALTER TABLE inventory ADD (gender varchar(15));
DROP statement
Drop is used to delete a table, database.
Syntax :
DROP DATABASE database_name;
DROP TABLE table_name;
Data Manipulation Language (DML)
Database language that enables insertion, deletion, modification, and retrieval of data from
database is called data manipulation language. Query language is only a part of data
manipulation language. SQL supports following DML statements:
1. Insert statement
2. Delete statement
3. Update statement
4. Select statement
INSERT statement
The insert command is used to insert data to the table.
Syntax:
INSERT into table_name values (data1, data2, data3 …);
INSERT INTO inventory
VALUES(101, 'Ujjwal', 'Dhumbarahi', 98555522, 'male');
INSERT INTO inventory
VALUES(102, 'Sujata', 'Chabhil', 98666622, 'female');
INSERT INTO inventory
VALUES(103, 'Suraj', 'Budanilkantha', 98263452, 'male');
INSERT INTO inventory
VALUES(104, 'Nir', 'Lubhu', 983432522, 'male');
INSERT INTO inventory
VALUES(105, 'Aarati', 'Gongabu', 98534532, 'female');
INSERT INTO inventory
VALUES(106, 'Bijay', 'Gwarko', 98532422, 'male');
INSERT INTO brands
VALUES(509, 'OPPO');
INSERT INTO brands
VALUES(504, 'VIVO');
INSERT INTO brands
VALUES(503, 'IPHONE');
INSERT INTO brands
VALUES(502, 'SAMSUNG');
INSERT INTO brands
VALUES(501, 'ONEPLUS');
INSERT INTO products
VALUES(901, 'oppo', 234, 20000);
INSERT INTO products
VALUES(902, 'vivo', 342, 25000);
INSERT INTO products
VALUES(903, 'samsung', 556, 40000);
INSERT INTO products
VALUES(904, 'Oneplus', 200, 70000);
INSERT INTO products
VALUES(905, 'Iphone', 100, 100000);
INSERT INTO store
VALUES(1, 'Kalanki mobiles', 'Kalanki', 98234222);
INSERT INTO store
VALUES(2, 'Chabhil mobiles', 'Chabhil', 98345345);
INSERT INTO store
VALUES(3, 'Newroad mobiles', 'Newroad', 98656465);
INSERT INTO store
VALUES(4, 'Gwarko mobiles', 'Gwarko', 98234324);
INSERT INTO store
VALUES(5, 'Koteshwor mobiles', 'Koteshwor', 983432422);
INSERT INTO categories
VALUES(401, 'phone');
INSERT INTO categories
VALUES(402, 'clothes');
INSERT INTO categories
VALUES(405, 'sports');
INSERT INTO categories
VALUES(403, 'household');
INSERT INTO categories
VALUES(404, 'electronics');
UPDATE statement
The update command is used to update a row of a table.
Syntax:
UPDATE table_name
SET column_name= value WHERE conditions;
UPDATE inventory
SET address='Bishalnagar'
WHERE userid = 101;
Table before updating :
Table after updating :
DELETE statement
The delete command is used to delete data from a table.
Syntax:
DELETE from table_name;
DELETE from inventory
where userid=106;
Table before deletion:
Table after deletion:
SELECT, FROM & WHERE CLAUSE
Select query is used to retrieve data from the tables. It is mostly used in SQL query.
FORM clause is used to choose relational table or database objects.
WHERE clause is used to specify condition while having retrieving data from the table. Where
clause is mostly used with select, update and delete query.
Syntax:
SELECT column_name1, column_name2
FROM table_name
WHERE [conditions];
SELECT prodname, prodprice
FROM `products`
WHERE prodprice > 25000;
AND operator
It is used in where clause. It returns the info of all the given conditions are satisfied, otherwise it
doesn’t display the information.
Syntax:
SELECT column_name[list]
FROM table_name
WHERE condition 1 AND condition 2 AND _ _ _ _AND condition n;
SELECT username, contact
FROM `inventory`
WHERE userid = 104 AND address = 'lubhu';
OR operator
It is used in where clause. It returns the info of anyone of the given conditions are satisfied,
otherwise it doesn’t display the information.
Syntax:
SELECT column_name[list]
FROM table_name
WHERE condition 1 OR condition 2 OR _ _ _ _OR condition n;
NOT operator
It is used in where clause. It returns the reverse or the opposite information.
Syntax:
SELECT column_name[list]
FROM table_name
WHERE NOT condition;
ORDER BY CLAUSE
It is used to define the value into order i.e. either ascending or descending order
Syntax:
ASCENDING ORDER DESCENDING ORDER
SELECT column_name [lists] SELECT column_name [lists]
FROM table_name FROM table_name
WHERE (conditions) WHERE (conditions)
ORDER BY column_name; ORDER BY column_name desc;
SELECT catname
FROM categories
WHERE catid > 403
ORDER BY catname ASC;
GROUP BY CLAUSE
It is used to group the result of a selected query based on one or more columns. It is also used
with SQL functions.
Syntax:
SELECT column_name [lists]
FROM table_name
WHERE condition(s)
GROUP BY column_name;
HAVING CLAUSE
It is used define the condition in GROUP BY CLAUSE. It is also used with SQL functions.
Syntax:
SELECT column_name [lists]
FROM table_name
WHERE condition(s)
GROUP BY column_name
HAVING conditions;
WILD CARD OPERATOR
It is used to search the specific pattern in a given string. The LIKE operator is used in wildcard
operator in order to define the conditions in SQL query.
LIKE clause is used in where clause to define the conditions in order to find out the specific
pattern from the set of character or strings. Type of operators:
1. % (Percentage) – to represent one or more character.
2. _ (Underscore) – to represent single character.
SELECT username, address, contact
FROM `inventory`
WHERE address LIKE 'B%';
SQL FUNCTION
SQL functions are useful while performing mathematical calculations, string
Concatenations, sub- strings etc.
• AGGREGATE FUNCTIONS
It returns a single value from the group of values.
1. AVG (): Average returns average value after calculating values in a numeric column.
Syntax:
SELECT AVG (column_name) FROM table_name
WHERE condition(s);
2. MAX (): MAX function returns maximum value from selected column of table.
Syntax:
SELECT MAX (column_name) FROM table_name
WHERE condition(s);
3. MIN (): MIN function returns minimum value from selected column of table.
Syntax:
SELECT MIN (column_name) FROM table_name
WHERE condition(s);
4. SUM (): SUM function returns total sum of a selected columns numeric values.
Syntax:
SELECT SUM (column_name) FROM table_name
WHERE condition(s);
5. COUNT (): COUNT returns the number of rows present in the table either based on some
condition or without any conditions.
Syntax:
SELECT COUNT (column_name) FROM table_name
WHERE condition(s);
6. FIRST (): It returns the first record.
Syntax:
SELECT FIRST (column_name) FROM table_name
WHERE condition(s);
7. LAST (): It returns the last record.
Syntax:
SELECT LAST (column_name) FROM table_name
WHERE condition(s);
• SCALAR FUNCTION
It is used to return the values of string or substring.
1. UCASE()
It is used to convert string into uppercase.
Syntax:
SELECT UCASE (column_name)
FROM table_name;
2. LCASE()
It is used to convert string into lowercase.
Syntax:
SELECT LCASE (column_name)
FROM table_name;
3. MID()
It is used to search the mid value.
Syntax:
SELECT MID (column_name,start,length)
FROM table_name;
4. ROUND()
It is used to round off the value of numeric.
Syntax:
SELECT ROUND (column_name)
FROM table_name;
SQL JOIN
A SQL Join statement is used to combine data or rows from two or more tables based on a
common field between them. Different types of Joins are:
1. INNER JOIN
2. OUTER JOIN
a. LEFT JOIN
b. RIGHT JOIN
c. FULL JOIN
3. CROSS JOIN
INNER JOIN
The INNER JOIN keyword selects all rows from both the tables as long as the condition
satisfies.
Syntax:
SELECT column_name[lists]
FROM table1
INNER JOIN table2
WHERE table1.column = table2.column
OUTER JOIN
Outer join returns the common value and remaining value from relations. There are three types
of outer join. They are:-
a) LEFT JOIN
LEFT JOIN returns all the rows of the table on the left side of the join and matching rows
for the table on the right side of join.
Syntax:
SELECT column_name[lists]
FROM table1
LEFT JOIN table2
WHERE table1.column = table2.column;
b) RIGHT JOIN
RIGHT JOIN returns all the rows of the table on the right side of the join and matching
rows for the table on the left side of join.
Syntax:
SELECT column_name[lists]
FROM table1
RIGHT JOIN table2
WHERE table1.column = table2.column;
c) FULL JOIN
FULL JOIN creates the result-set by combining result of both LEFT JOIN and RIGHT
JOIN. The result-set will contain all the rows from both the tables. The rows for which
there is no matching, the result-set will contain NULL values.
Syntax:
SELECT column_name[lists]
FROM table1
FULL JOIN table2
WHERE table1.column = table2.column;