0% found this document useful (0 votes)
13 views23 pages

Adbms 1

The document outlines the development and features of an Employee Management System (EMS) using MongoDB and Flask, emphasizing its efficiency in managing employee data and reducing redundancy. It also explains the Extended Entity-Relationship Diagram (EERD) for complex database design, along with the relational model and SQL commands for database operations. Additionally, it provides a comprehensive overview of MongoDB, including installation instructions and examples of NoSQL commands for managing data.

Uploaded by

Rajun Pandey
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)
13 views23 pages

Adbms 1

The document outlines the development and features of an Employee Management System (EMS) using MongoDB and Flask, emphasizing its efficiency in managing employee data and reducing redundancy. It also explains the Extended Entity-Relationship Diagram (EERD) for complex database design, along with the relational model and SQL commands for database operations. Additionally, it provides a comprehensive overview of MongoDB, including installation instructions and examples of NoSQL commands for managing data.

Uploaded by

Rajun Pandey
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/ 23

Introduction:

An Employee Management System (EMS) is essential for managing employee-related data


efficiently, such as personal details, job information, and contact information. Developed using
MongoDB and Flask on Python, the EMS aims to streamline the handling of employee data,
improving operational efficiency and reducing redundancy.

Identifying the limitations of the current manual or outdated systems has led to the
development of this computerized system, which is designed to be user-friendly and more
graphical in its user interface (GUI). The manual system often suffers from data redundancy,
inefficiency, and a higher likelihood of errors. The automated system addresses these issues,
providing several benefits:

1. Cost Efficiency: The EMS significantly reduces the management costs associated with
paperwork and minimizes the number of personnel required for administrative tasks.
2. Centralized Information Sharing: The system provides a unified platform for
administrators to disseminate information and notices regarding policies, events, and
updates through a virtual notice board.
3. Enhanced Transparency: The EMS ensures transparent record-keeping and data
management, which helps in maintaining accurate and up-to-date employee records.

Extended Entity Relationship Model

An Extended Entity-Relationship Diagram (EERD) is an advanced version of the traditional


Entity-Relationship Diagram (ERD) used in database design. EERDs include additional
concepts and features to model more complex relationships and constraints in a database
schema. Here are some key elements and notations commonly used in an Extended Entity-
Relationship Diagram:

1. Entities: Entities represent real-world objects or concepts. They are typically


depicted as rectangles with the entity name inside.
2. Attributes: Attributes describe the properties or characteristics of entities. They are
shown as ovals connected to their respective entities by lines. Each attribute has a
name and a data type.
3. Key Attributes: Key attributes uniquely identify each entity within its set. They
are underlined or marked with a key symbol.
4. Derived Attributes: Derived attributes are attributes whose values can be
calculated from other attributes in the database. They are represented with a dashed
oval.
5. Relationships: Relationships describe how entities are related to each other. They
are represented as diamond shapes connecting the related entities. The cardinality
and participation constraints of relationships can be indicated near the diamonds.
6. Cardinality Constraints: These constraints specify the number of instances of one
entity that can be related to the other entity. Common notations are "1" (one) and
"M" (many).
7. Participation Constraints: These constraints specify whether the participation of
entities in a relationship is mandatory (total) or optional (partial).
8. Roles: In some cases, the same entity can participate in multiple roles within a
single relationship. Roles help clarify the purpose of an entity within a specific
relationship.
9. Multivalued Attributes: Multivalued attributes are attributes that can have
multiple values for a single entity. They are represented with a double oval.
10. Weak Entities: Weak entities are entities that do not have a primary key attribute
on their own. They rely on a relationship with a strong entity (called the identifying
or owning entity) for identification.
11. Specialization and Generalization: EERDs allow for the modeling of hierarchical
relationships between entities through specialization and generalization. An entity
can be specialized into subtypes, and generalization represents a higher-level entity
that encompasses multiple subtypes.
12. Union Types: Union types are used to represent an entity that can be one of several
entity types. It is typically depicted as a circle with labeled arcs pointing to the
possible entity types.
13. Aggregation: Aggregation represents a higher-level entity composed of related
entities. It is depicted as a diamond shape with a line connecting it to the aggregated
entities.
14. Constraints: Constraints can be added to specify additional rules and requirements
for the database schema, such as uniqueness constraints, referential integrity
constraints, or check constraints.

Extended Entity-Relationship Diagrams are particularly useful for designing complex


databases with intricate relationships and constraints. They provide a more comprehensive
and structured way to model data compared to traditional ERDs, making them valuable
tools in database design and development.

EER diagram:

Figure 1: EER diagram of Employee Management System


Mapping the EER diagram to Relational table

The relational model represents how data is stored in Relational Databases. A relational
database consists of a collection of tables, each of which is assigned a unique name.
The relational model can represent a table with columns and rows. Each row is known as a
tuple.
Each table of the column has a name or attribute.
Properties of Relation:
1. The name of the relation is distinct from all other relations.
2. Each relation cell contains exactly one atomic (single) value
3. Each attribute contains a distinct name
4. The attribute domain has no significance
5. tuple has no duplicate value
6. The order of tuples can have a different sequence

A database is an organized collection of structured information, or data, typically stored


electronically in a computer system. A database is usually controlled by a database
management system (DBMS). Together, the data and the DBMS, along with the applications
that are associated with them, are referred to as a database system, often shortened to just a
database.
Data within the most common types of databases in operation today is typically modeled in
rows and columns in a series of tables to make processing and data querying efficient. The data
can then be easily accessed, managed, modified, updated, controlled, and organized. Most
databases use structured query language (SQL) for writing and querying data.
Employee:

Department:

Dept_location:
Project:

Works_on:

Dependent:
Relation Model of E-Commerce application:

Figure 2: Designer Relationship of E-commerce application

SQL commands in Relational Databases with stored procedure and


Triggers:

Create table category:


Insert multiple data into database:

Drop the table:

To delete data:

To delete records:

To alter the table:


Join:

Inner join:

Left join:

Right join:
View:

Selecting data from view:


Creating procedure:
DELIMITER //

CREATE PROCEDURE GetEmployeeCount()


BEGIN
SELECT COUNT(*) AS EmployeeCount FROM EMPLOYEE;
END //

DELIMITER ;

CALL GetEmployeeCount();
Creating trigger:

Inserting data after creating trigger:

Selecting data from department:


Subquery with exists:

Subquery with Not exists:


Introduction to MongoDB
MongoDB is a popular, open-source NoSQL database that is designed for flexibility, scalability,
and ease of development. It belongs to the document-oriented database category and is known
for its ability to handle unstructured or semi-structured data. Here's an overview of key
concepts and features related to MongoDB:

1. Document-Oriented Database:
MongoDB stores data in a format called BSON (Binary JSON), which is a binary
representation of JSON-like documents.Each document can have a different structure,
making MongoDB flexible for accommodating data of varying shapes.
2. Collections: MongoDB organizes data into collections, which are similar to tables in
relational databases. Collections can contain multiple documents, and documents within a
collection do not need to have the same fields.
3. Documents: A document is a single record in MongoDB, represented as a JSON-like
object. Documents can contain nested subdocuments and arrays.
4. Fields: Fields are key-value pairs within a document. Field names are case-sensitive.
5. ObjectId: MongoDB automatically assigns a unique ObjectId to each document as its
primary key. This field is typically named _id.
6. Indexes: MongoDB supports indexing for efficient querying. Indexes can be created
on single fields, compound fields, or arrays to improve query performance.
7. Query Language: MongoDB uses a powerful query language for searching and
filtering documents. Queries can use a wide range of operators, including equality,
comparison, and logical operators.
8. Aggregation Framework: MongoDB provides a flexible aggregation framework for
performing complex data transformations, grouping, and computation operations on data.
9. Replication: MongoDB supports replica sets, which are clusters of MongoDB servers
that maintain the same data for redundancy and high availability. Replica sets provide
automatic failover and data redundancy.
10. Sharding: MongoDB can horizontally scale by using sharding. Sharding divides data
across multiple servers based on a shard key, allowing for distribution of data and queries.
11. Transactions: Starting with MongoDB 4.0, MongoDB supports multi-document
transactions, making it suitable for applications requiring ACID (Atomicity, Consistency,
Isolation, Durability) transactions.
12. Geospatial Data:MongoDB has built-in support for geospatial data and geospatial
indexing, allowing for location-based queries.
13. Security:MongoDB offers various security features, including authentication,
authorization, and encryption.Role-based access control (RBAC) can be used to manage
user permissions.

Installation of MongoDB
To install MongoDB on a Windows operating system, follow these step-by-step instructions:

Step 1: Download MongoDB

• Visit the official MongoDB website at


https://www.mongodb.com/try/download/community.
• Scroll down to the "Community Server" section, where you can download the
MongoDB software for free.
• Under the "Windows" subsection, locate and click on the "Download" button to initiate
the download of the latest stable version of MongoDB for Windows.

Step 2: Run the Installer

• After the download is complete, locate the downloaded installer file, typically found in
the computer's "Downloads" folder.
• Double-click on the installer file to execute it and begin the installation process.

Step 3: Choose Setup Type

• The MongoDB Setup Wizard will appear on the screen. Click the "Next" button to
proceed.
• Select the "Complete" setup type, which includes both the MongoDB server and
associated tools. Click "Next" to continue.

Step 4: Service Configuration


• You will be presented with the option to configure MongoDB to run as a Windows
service. It is recommended to leave this option enabled, as it ensures that MongoDB
starts automatically when the computer boots up.
• Optionally, customize the data directory, but most users can stick with the default
location. Click "Next" to proceed.

Step 5: Install MongoDB Compass (Optional)

• MongoDB Compass is a graphical user interface (GUI) for MongoDB. Decide whether
to install it or not. If chosen, click "Next."

Step 6: Ready to Install

• Review the installation settings displayed on the screen. If everything looks correct,
click the "Install" button to initiate the installation process.

Step 7: Installation Progress

• The installer will now copy the necessary files and set up MongoDB on the Windows
system. This may take a few minutes to complete.

Step 8: Completing the MongoDB Setup

• Once the installation is finished, a screen labeled "Completing the MongoDB Setup"
will appear. Decide whether to install MongoDB Compass (the GUI) by checking or
unchecking the corresponding option. Then, click "Next" to proceed.

Step 9: Installation Complete

• A screen indicating the successful installation will appear. Ensure that the "Run the
MongoDB shell" option is checked if you want to open the MongoDB shell
immediately. Then, click "Finish" to finalize the installation.

Step 10: Verify Installation

• To verify that MongoDB has been successfully installed, open either the Windows
Command Prompt (CMD) or PowerShell.
• Type "mongo" and press Enter. If MongoDB is installed correctly, this action will open
the MongoDB shell, confirming the successful installation.
Setup command for run the queries

To run queries in MongoDB, one typically utilizes the MongoDB shell, a command-line
interface for interacting with MongoDB. The following are the basic steps to execute queries
using the MongoDB shell:

Step 1: Opening the MongoDB Shell

• Open the command prompt or terminal window.

Step 2: Connecting to the MongoDB Server

• Utilize the "mongo" command followed by the hostname and port of the MongoDB
server to establish a connection. MongoDB typically runs on the localhost at port 27017
by default. If MongoDB is hosted on a different server or port, replace the placeholders
accordingly.

mongo --host hostname --port port

For instance, to connect to the default MongoDB instance running locally:


mongo

Step 3: Selecting a Database

• After successfully connecting to the MongoDB server, select a specific database using
the "use" command.

use your_database_name

• Replace "your_database_name" with the name of the database to be used. MongoDB


will create the database if it does not already exist.

Step 4: Executing Queries

• Once a database has been selected, MongoDB queries can be executed. Below are some
common query examples:
1. Finding documents in a collection:

db.your_collection_name.find({ key: value })


2. Inserting a document into a collection:

db.your_collection_name.insert({ key: value })

3. Updating documents in a collection:

db.your_collection_name.update({key: value},{ $set:{ new_key: new_value }})

4. Deleting documents from a collection:

db.your_collection_name.remove({ key: value })

• Replace "your_collection_name," "key," "value," "new_key," and "new_value" with


the actual collection and field names, as well as the specific values intended for
querying or modification.

Step 5: Exiting the MongoDB Shell

• When finished working with the MongoDB shell, exit by typing "exit" or pressing "Ctrl
+ C."

Run NoSQL commands

i. Create database shopping and create collection


ii. Insert in collection department and find the data:
>db.DEPARTMENT.insertOne({
Dname: "HR", Dnumber: 4, Mgr_ssn: 121314151, Mgr_start_date: new Date("2022-
04-01")})

ii. Insert in collection project and find the data:


> db.PROJECT.insertOne({ Pname: "Project D", Pnumber: 104, Plocation:
"Chicago", Dnum: 1 })
iv. Insert in collection dept_location and find the data:
> db.DEPT_LOCATIONS.insertOne({ Dnumber: 4,Dlocation: "Boston"})

v. Insert in collection employee and find the data:


> db.EMPLOYEE.insertMany([{ Fname: "Salina", Mname: A", Lname: "Gurung",
Ssn: 223344558, Bdate: new Date("2000-01-01"), Address: "456 Elm St", Sex:
"Female", Salary: 70000, Dno: 3 },{ Fname: "Ashma", Mname: "S", Lname:
"Ghimire", Ssn: 223344559, Bdate: new Date("1992-02-02"), Address: "101 Maple
St", Sex: "Female", Salary: 80000, Dno: 4 }])

vi. Insert in collection works_on and find the data:


> db.WORKS_ON.insertMany([{ Essn: 223344556, Pno: 101, Hours: 10 },{ Essn:
223344557, Pno: 102, Hours: 15 }])
Q. Find the first Name, address, salary, department name and department
location and project name for every employee:
NoSQL:
db.EMPLOYEE.aggregate([
{$lookup: {
from: "DEPARTMENT",
localField: "Dno",
foreignField: "Dnumber",
as: "department"}},
{$unwind: "$department"},
{$lookup: {
from: "DEPT_LOCATIONS",
localField: "Dno",
foreignField: "Dnumber",
as: "department_location"}},
{$unwind: "$department_location"},
{$lookup: {
from: "WORKS_ON",
localField: "Ssn",
foreignField: "Essn",
as: "works_on"}},
{$unwind: "$works_on},
{$lookup: {
from: "PROJECT",
localField: "works_on.Pno",
foreignField: "Pnumber",
as: "project"}},
{$unwind: "$project"},
{$project: {
_id: 0,
Fname: 1,
Address: 1,
Salary: 1,
"department.Dname": 1,
"department_location.Dlocation": 1,
"project.Pname": 1
}}]).pretty()
Output:
Conclusion:

In this Advanced Database practical, we learned about following:


• Learned how to designed Extended Entity Relationship(EER) Diagram.
• Get Knowledge of how EER diagram is converted to relational table.
• Had idea of how EER is implemented in SQL.
• Learned about various SQL queries for SQL Data Definition language (create, alter,
drop) and Data Manipulation language (select, insert, alter, aggregate, join etc.) queries.
• Get idea of Trigger and Active Procedure.
• Had knowledge of JOIN, view and procedure.
• Learned about MongoDB installation and create of database and collections.
• Get idea of how data are inserted in collections and find the data.
• Knowledge of extracting data from multiple collection using aggregate, lookup.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy