Sample 1
Sample 1
: 1
QUERY OPTIMIZER
PROBLEM STATEMENT:
You are given a relational database containing information about a college. Create and insert
the values into the ` database includes tables such as Students, Courses, Enrollments,
Departments, and Professors. Write optimized SQL queries to retrieve data efficiently.
Tasks:
1. Create and Insert the values into the database. And display the values from the
database.
2. Retrieve Table Metadata:
o Write SQL queries to fetch metadata about the Students table, including
column names, data types, and constraints.
o Based on the metadata, identify which columns are indexed and which are not.
You need to fetch the names of all students enrolled in a specific course. The course is
identified by its CourseID.
Check if there is an index on the CourseID column in the Enrollments table. If not,
create an index on CourseID.
Write an optimized query to fetch the student names.
Use EXPLAIN or a similar tool to analyze the performance of the query before and
after indexing. Record the changes in execution time or cost.
INTRODUCTION: "Query with optimizer by accessing the metadata" refers to the process
in which a database management system (DBMS) uses an internal component called a query
optimizer to determine the most efficient way to execute a database query. The optimizer
makes decisions based on metadata, which is data that provides information about the
structure and characteristics of the database.
1. Query:
o A request to retrieve or manipulate data stored in a database. For example, a
SQL query might request all records from a table where a certain condition is
met.
2. Optimizer:
o A software component within the DBMS that analyzes different ways to
execute a query. It considers various strategies or "execution plans" to find the
one that will complete the task most efficiently, often measured in terms of
time and resource usage (like CPU, memory, and I/O operations).
3. Metadata:
o Data about the data stored in the database. This includes information like:
The size of tables.
The number of rows in a table.
The distribution of values within columns.
The presence and type of indexes.
Data types and constraints on columns.
o Metadata helps the optimizer understand the characteristics of the data, which
is crucial for making informed decisions about the best way to execute a
query.
OBJECTIVES:
The objective is to create and insert values into the database, retrieve metadata, optimize
queries using metadata, and evaluate query performance to ensure efficient data retrieval.
APPLICATIONS:
STEP-BY-STEP-PROCESS:
Step 2: Create Tables: Students Table, Courses Table, Enrollments Table, Department
Step 4: Display the Values: To display data from the Students table, Courses Table,
Step 1: Fetch Metadata for the Students Table: Get column names, data types, and
constraints, Get detailed information about the Students table:
AIM:
To design a relational database for a college that contains information about students,
courses, enrollments, departments, and professors.
ALGORITHMS:
1. Write SQL queries to fetch metadata about the Students table, including column
names, data types, and constraints.
o Use the SHOW COLUMNS or DESCRIBE commands to retrieve this
information.
2. Identify indexed and non-indexed columns by querying the
INFORMATION_SCHEMA or using the SHOW INDEX command.
1. Use the EXPLAIN command to analyze the query execution plan before and after
indexing the CourseID column.
o Compare the results to observe the impact of indexing on query performance.
2. Record the changes in execution time, cost, and other relevant metrics to assess the
optimization's effectiveness.
Step 6: Conclude
1. Summarize the outcomes of the database creation, data insertion, metadata retrieval,
query optimization, and performance evaluation.
2. End the process.
IMPLEMENTATION:
Courses Table:
Enrollments Table:
Departments Table:
Professors Table:
OUTPUT:
Display the Values
To display data from the Students table:
RESULT: Thus to create to optimize queries for an XML database that stores college data,
specifically focusing on retrieving student information has been successfully executed.
Ex.No.: 2
DISTRIBUTED DATABASE
Create a distributed database and run various queries Use stored procedures
PROBLEM STATEMENT:
Problem Statement:
INTRODUCTION:
Manage tables across distributed databases, perform data insertion, and run various queries to
combine and aggregate data.
APPLICATIONS:
E-commerce Platforms
Financial Services
Healthcare Systems
Social Media Networks
STEP-BY-STEP EXPLANATION:
Task 2: Insert Sample Data into the Employees Tables in Each Database
Connect to Database1 and insert sample data into the Employees table.
Connect to Database2 and insert different sample data into the Employees table.
Task 3: Combine Data from the Employees Tables in Both Databases Using the UNION
Operator
Modify the previous UNION query to include duplicate records using UNION ALL.
Task 6: Query the View to Display Total Salary for Each Department
Write a query to retrieve data from the view EmployeeSalaryByDepartment to display
the total salary for each department.
AIM: To create a distributed database system and perform various operations using stored
procedures,
ALGORITHM:
IMPLEMENTATION:
Create Tables
Database1:
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
Name VARCHAR(50),
DepartmentID INT,
SalaryID INT
);
Database2:
Insert Data
Database1:
Database2:
SELECT DepartmentName,
EmployeeCount,
TotalSalary,
AverageSalary
FROM EmployeeSummary;
OUTPUT:
RESULT: Thus to create and manage tables in two distributed databases, insert data,
combine data using SQL operations, handle duplicates, and aggregate information has been
successfully executed.
Ex.No.: 3
OBJECT-ORIENTED DATABASE
Create OQL Queries to access the data from Object Oriented Database.
PROBLEM STATEMENT:
Data Retrieval
Retrieve all employees.
Retrieve employees by department
Update Records:
Object Query Language (OQL) is a query language specifically designed for Object-
Oriented Database Management Systems (OODBMS). It is used to query and manipulate
objects stored in an OODBMS, much like how SQL is used in relational databases. OQL
allows you to query data while leveraging the object-oriented features such as inheritance,
encapsulation, and polymorphism.
OBJECTIVES:
This system will allow operations such as inserting, retrieving, updating, and deleting
employee and department records across the distributed nodes.
STEP-BY-STEP PROCESS:
Database Creation: On one of the nodes, create a distributed database instance (e.g.,
EmployeeDB).
Connection Setup: Define and configure database connections between nodes.
Ensure the database is accessible from all nodes in the cluster.
Employee Class:
o Properties: EmployeeID, Name, Salary, DepartmentID
Department Class:
o Properties: DepartmentID, DepartmentName
Relationships: Define a foreign key relationship between Employee and Department
using DepartmentID.
Data Retrieval
Update Records
Delete Records
AIM:
The aim of this project is to configure a distributed database system across multiple nodes for
an employee management system
ALGORITHM:
IMPLEMENTATION:
Database Creation: On one of the nodes, create a distributed database instance (e.g.,
EmployeeDB).
Connection Setup: Define and configure database connections between nodes.
Ensure the database is accessible from all nodes in the cluster.
Create Basic Classes
Employee Class:
o Properties: EmployeeID, Name, Salary, DepartmentID
Department Class:
o Properties: DepartmentID, DepartmentName
Relationships: Define a foreign key relationship between Employee and Department
using DepartmentID.
Database1:
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
Name VARCHAR(50),
DepartmentID INT,
SalaryID INT
);
Database2:
Sample Records:
sql
Copy code
INSERT INTO Employee (EmployeeID, Name, Salary, DepartmentID) VALUES (1,
'John Doe', 50000, 101);
INSERT INTO Employee (EmployeeID, Name, Salary, DepartmentID) VALUES (2,
'Jane Smith', 60000, 102);
Insert Records into Department Class
Sample Records:
sql
Copy code
INSERT INTO Department (DepartmentID, DepartmentName) VALUES (101, 'HR');
INSERT INTO Department (DepartmentID, DepartmentName) VALUES (102, 'IT');
Data Retrieval
sql
Copy code
SELECT * FROM Employee;
sql
Copy code
SELECT * FROM Employee WHERE DepartmentID = 101;
sql
Copy code
SELECT * FROM Employee WHERE Salary > 55000;
sql
Copy code
SELECT e.Name, d.DepartmentName FROM Employee e JOIN Department d ON
e.DepartmentID = d.DepartmentID;
sql
Copy code
SELECT * FROM Employee ORDER BY Salary DESC;
Retrieve Department-wise Employee Count:
sql
Copy code
SELECT DepartmentID, COUNT(*) as EmployeeCount FROM Employee GROUP
BY DepartmentID;
Update Records
sql
Copy code
UPDATE Employee SET Salary = Salary * 1.10 WHERE DepartmentID = 102;
sql
Copy code
UPDATE Employee SET DepartmentID = 101 WHERE EmployeeID = 2;
Delete Records
sql
Copy code
DELETE FROM Employee WHERE EmployeeID = 1;
sql
Copy code
DELETE FROM Employee WHERE DepartmentID = 102;
Retrieve and display outputs from the above SQL queries to show the result of
each operation.
OUTPUT:
RESULT: Thus to create and manage tables in two distributed databases, insert data,
combine data using SQL operations, handle duplicates, and aggregate information has been
successfully executed.
Ex.No.: 4
PARALLEL DATABASE
1. Install and configure a parallel database system and Java development environment.
(Ex. Apache HBase)
2. Write Java code to establish a connection to the parallel database.
3. Execute basic SQL queries against the parallel database
INTRODUCTION:
Parallel databases are designed to handle large volumes of data by distributing the workload
across multiple processors or servers. This architecture allows for faster query processing,
improved scalability, and better fault tolerance compared to traditional single-node databases.
1. Data Partitioning: Data is split across multiple disks or nodes. Common partitioning
methods include:
o Horizontal Partitioning: Dividing rows across different nodes.
o Vertical Partitioning: Dividing columns across different nodes.
o Hash Partitioning: Distributing data based on a hash function.
o Range Partitioning: Dividing data based on a range of values.
2. Parallel Query Execution: Queries are processed simultaneously by different
processors or nodes. Techniques include:
o Intra-query parallelism: Breaking a single query into sub-tasks that run in
parallel.
o Inter-query parallelism: Running multiple queries simultaneously across
different processors.
3. Load Balancing: Ensuring that data and query processing is evenly distributed across
nodes to prevent bottlenecks.
4. Fault Tolerance: If one node fails, the system can continue processing using the
remaining nodes, often with data replication to ensure no data is lost.
OBJECTIVES:
To develop an application in Java that can efficiently interact with a parallel database system
to perform various data operations, including querying, updating, and managing data across
distributed nodes.
APPLICATION:
Data Warehousing
Big Data Analytics
Scientific Research
Financial Services
Telecommunications
Health Care
STEP-BY-STEP EXPLANATION:
1. Schema Design
3. Parallel Setup
Sharding: Distribute the tables across different nodes based on UnitID or other criteria
to balance the load.
Replication: Implement replication to ensure fault tolerance and high availability.
4. Basic Queries
Retrieve all personnel information, including their unit names and roles:
Find all missions conducted by a specific unit, including details about the personnel
assigned to those missions and the equipment used:
alculate the total number of missions conducted by each unit and the average duration
of these missions:
Generate a report listing the top 5 units with the highest number of missions,
including the total number of missions and average mission duration for each unit:
Aim:
Algorithms:
Setup and Configuration: Install and configure HBase, ensuring it's properly
integrated with the Java development environment.
Connection Establishment: Write Java code to connect to HBase.
CRUD Operations: Implement Java code to perform INSERT, SELECT, UPDATE,
and DELETE operations.
Parallel Operations: Use concurrency utilities to perform batch operations and
measure performance.
Query Optimization: Use HBase-specific techniques and tools to optimize query
performance.
1. Download HBase: Download the latest HBase binary from the Apache HBase
website.
2. Extract the Archive:
3. Configure HBase:
o Navigate to the conf directory inside the HBase installation directory.
o Edit the hbase-site.xml file to configure HBase. Add the following properties
for a basic setup:
4. Start HBase:
5. Verify Installation:
o Open HBase Shell:
o Check the status:
IMPLEMENTATION:
1. Download HBase: Download the latest HBase binary from the Apache HBase
website.
2. Extract the Archive:
bash
Copy code
tar xzf hbase-x.y.z-bin.tar.gz
3. Configure HBase:
o Navigate to the conf directory inside the HBase installation directory.
o Edit the hbase-site.xml file to configure HBase. Add the following properties
for a basic setup:
xml
Copy code
<configuration>
<property>
<name>hbase.root.logger</name>
<value>INFO,console</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/tmp/zookeeper</value>
</property>
<property>
<name>hbase.master</name>
<value>localhost:16000</value>
</property>
<property>
<name>hbase.regionserver.port</name>
<value>16020</value>
</property>
</configuration>
4. Start HBase:
bash
Copy code
./bin/start-hbase.sh
5. Verify Installation:
o Open HBase Shell:
bash
Copy code
./bin/hbase shell
hbase
Copy code
status 'detailed'
2. Write Java Code to Establish a Connection to HBase
You'll need the HBase client library in your Java project. You can include it via Maven or
download it manually.
Here’s an example of how to establish a connection using Java:
java
Copy code
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
System.out.println("Data inserted!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Select Data
java
Copy code
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
} catch (Exception e) {
e.printStackTrace();
}
}
}
Update Data
You use Put for updating data in HBase as well.
Delete Data
java
Copy code
import org.apache.hadoop.hbase.client.Delete;
System.out.println("Data deleted!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
4. Perform Parallel Data Operations
For parallel operations, use Java's ExecutorService.
Batch Inserts Example
java
Copy code
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class HBaseBatchInsertExample {
executor.shutdown();
}
}
Parallel Queries Example
You can use a similar approach to perform parallel queries.
OUTPUT:
RESULT: Thus to design and implement a parallel database system to manage employee
information, including personnel, missions, and equipment has been successfully executed
Ex.No.: 5
ACTIVE DATABASES
Create a Active database with facts and extract data using rules.
PROBLEM STATEMENT:
Problem Statement: Design and implement a database for managing sales information. Your
database should include tables for customers, orders, and products. Set up the schema and
populate the tables with sample data. Implement triggers to automate specific actions in the
sales database. Focus on creating triggers that automatically update certain fields or enforce
business rules when data is inserted, updated, or deleted.
Tasks:
1. Schema Design:
o Create the following tables:
Customers: CustomerID, CustomerName, ContactEmail
Products: ProductID, ProductName, Price
Orders: OrderID, CustomerID, OrderDate, TotalAmount
OrderItems: OrderItemID, OrderID, ProductID, Quantity, ItemTotal
2. Sample Data Insertion:
o Populate each table with sample data to represent a sales scenario.
3. Basic Query:
o Write a query to retrieve all orders along with customer names and product
details.
Create a trigger that automatically calculates and updates the TotalAmount in the Orders
table whenever a new order is inserted or an OrderItems record is modified.
Create a trigger that automatically updates product inventory levels in the Products table
whenever an OrderItems record is inserted or updated.
Test the triggers by inserting and updating records in the Orders and OrderItems tables.
Verify that the TotalAmount and inventory levels are correctly updated.
Create an assertion that ensures the TotalAmount in the Orders table is equal to the sum of
ItemTotal values in the OrderItems table for that order.
Create an assertion that enforces a minimum quantity rule, such as ensuring that no
OrderItems record has a quantity less than 1.
Test the assertions by attempting to insert or update records that violate the rules. Verify that
the assertions prevent these invalid operations.
INTRODUCTION:
An active database is a type of database that integrates data storage with intelligent
processing capabilities. It actively monitors and reacts to changes or events within the
database by applying predefined rules. This approach extends the traditional database model
by allowing automatic, event-driven responses and decisions based on the current state of the
data.
1. Facts:
o Definition: Facts are discrete pieces of information stored in the database.
They represent the current state or knowledge about entities in the domain.
o Example: In a customer database, facts might include "Customer A purchased
Product X" or "Product Y is in stock."
2. Rules:
o Definition: Rules are logical expressions that define how to derive new
information or trigger actions based on the existing facts.
o Structure: Typically expressed in an "IF-THEN" format. For instance, "IF a
customer's purchase amount exceeds $1000, THEN apply a 10% discount."
o Purpose: Rules enable the database to make decisions, infer new data, or
automate responses without manual intervention.
3. Event-Condition-Action (ECA) Model:
o Definition: A common paradigm in active databases where actions are
triggered based on specific events and conditions.
o Components:
Event: A change or occurrence within the database or an external
event that prompts the database to act.
Condition: A test applied to determine if the event meets certain
criteria.
Action: The response or activity executed if the condition is satisfied.
4. Inference Engine:
o Definition: The component responsible for applying rules to facts to derive
new information or trigger actions.
o Functionality: Evaluates which rules apply to the current set of facts and
performs the necessary actions.
APPLICATIONS:
STEP-BY-STEP EXPLANATION:
1. Schema Design: Define tables for Customers, Products, Orders, and OrderItems.
2. Sample Data Insertion: Insert sample records into each table to simulate a sales
scenario.
3. Basic Query: Write a SQL query to retrieve orders along with customer names and
product details.
4. Triggers:
o Create a trigger to automatically update the TotalAmount in the Orders table
when new records are inserted or updated in the OrderItems table.
o Create a trigger to automatically update the inventory levels in the Products
table whenever an OrderItems record is inserted or updated.
5. Assertions:
o Create an assertion to ensure TotalAmount in the Orders table matches the
sum of ItemTotal in the OrderItems table.
o Create an assertion to enforce a minimum quantity rule for OrderItems.
6. Testing:
o Insert and update records to test triggers.
o Attempt invalid operations to test assertions.
AIM:
The aim is to create a relational database that manages sales information by tracking
customers, products, orders, and order items.
ALGORITHMS:
1. Schema Design: Define tables for Customers, Products, Orders, and OrderItems.
2. Sample Data Insertion: Insert sample records into each table to simulate a sales
scenario.
3. Basic Query: Write a SQL query to retrieve orders along with customer names and
product details.
4. Triggers:
o Create a trigger to automatically update the TotalAmount in the Orders table
when new records are inserted or updated in the OrderItems table.
o Create a trigger to automatically update the inventory levels in the Products
table whenever an OrderItems record is inserted or updated.
5. Assertions:
o Create an assertion to ensure TotalAmount in the Orders table matches the
sum of ItemTotal in the OrderItems table.
o Create an assertion to enforce a minimum quantity rule for OrderItems.
6. Testing:
o Insert and update records to test triggers.
o Attempt invalid operations to test assertions.
IMPLEMENTATIONS:
1. Schema Design
The schema consists of four tables: Customers, Products, Orders, and OrderItems. Each table
will have a set of fields as described.
SQL Statements for Table Creation
CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
CustomerName VARCHAR(100),
ContactEmail VARCHAR(100)
);
5. Testing Triggers
Test the triggers by inserting and updating records in the Orders and OrderItems tables.
Sample Test Data Insertion
-- Insert a new order item
INSERT INTO OrderItems (OrderItemID, OrderID, ProductID, Quantity, ItemTotal)
VALUES (4, 1, 3, 1, 299.99);
6. Implementing Assertions
Assertions are constraints that enforce rules on the data. Although not all databases support
the ASSERTION keyword directly, the same effect can be achieved using CHECK
constraints or triggers.
Assertion for TotalAmount Validation
CREATE TRIGGER ValidateOrderTotal
AFTER INSERT OR UPDATE ON Orders
FOR EACH ROW
BEGIN
DECLARE calculatedTotal DECIMAL(10, 2);
SELECT SUM(ItemTotal) INTO calculatedTotal
FROM OrderItems
WHERE OrderID = NEW.OrderID;
OUTPUT:
Customers Table
Products Table:
Orders Table:
OrderItems Table:
RESULT: Thus to design and implement a production database with tables for products,
production orders, and inventory has been successfully executed
Ex.No.: 6
DEDUCTIVE DATABASE
Create a knowledge database with facts and extract data using rules
PROBLEM STATEMENT:
To use Datalog to create and query a deductive database that manages information
about birds and their characteristics. You will define facts and rules in Datalog to
infer new information and answer queries.
Set Up Environment:
Use a Datalog implementation or a knowledge base system that supports Datalog
(e.g., SWI-Prolog, LogicBlox).
Define Facts:
Create a set of facts about birds, including their characteristics such as habitat, diet,
and size.
Define Rules:
Define rules to infer new information based on the facts
Query the Database:
Write queries to retrieve information based on the facts and rules defined.
Add New Facts and Rules:
Extend the database with additional facts and rules.
Test and Validate:
Test the queries with the extended facts and rules.
Validate that the queries return the expected results based on the new facts and rules.
INTRODUCTION:
APPLICATIONS:
1. Expert Systems
Medical Diagnosis:
Legal Reasoning:
2. Data Integration
Semantic Data Integration:
Ontology Management:
Fraud Detection:
Compliance and Policy Enforcement:
Semantic Parsing:
Information Extraction:
Reasoning in AI:
Explanation Generation:
6. Semantic Web
7. Cognitive Computing.
STEP-BY-STEP PROCESS:
Facts: Basic assertions about the world, similar to tuples in a relational database.
Rules: Logical statements that define relationships between facts, allowing the
inference of new facts.
In Prolog, the knowledge base is a file that contains facts and rules. Create a file named
birds.pl:
AIM: To create and query a deductive database using Datalog to manage and infer
information about birds and their characteristics, such as habitat, diet, and size.
ALGORITHMS:
Set Up Environment:
Define Facts:
Represent information about birds using facts. Facts are basic assertions about entities
in the database.
Example facts could include habitat, diet, and size of various bird species.
Define Rules:
Create rules to infer new information based on the existing facts. Rules use logical
inference to derive conclusions from facts.
For example, a rule might infer that a bird is endangered if it has a specific diet and
habitat.
IMPLEMENTATION:
Define facts:
% Facts about birds
bird(eagle).
bird(pigeon).
bird(sparrow).
bird(parrot).
Define Rules:
Write Queries:
% Query to find all birds that are both urban and small
?- urban_and_small_bird(Bird).
% Expected output: Bird = sparrow.
OUTPUT:
Here’s a sample output for each query when using the facts and rules defined:
?- small_bird(Bird).
4. Query to find all birds that are both urban and small
?- urban_and_small_bird(Bird).
?- medium_bird(Bird).
RESULT: Thus to create and query a deductive database using Datalog to manage and infer
information about birds and their characteristics, such as habitat, diet, and size has been
successfully executed
Ex.No.: 7
ETL TOOL
To extract data from your transactional system to create a consolidated data
warehouse or data mart for reporting and analysis.
Problem Statement: Design and implement a basic ETL process to integrate production and
sales data from multiple sources into a centralized database. The goal is to extract data from
source systems, transform it to fit the target schema, and load it into the database.
Tasks:
INTRODUCTION:
ETL (Extract, Transform, Load) tools are software applications used to manage the process
of extracting data from various sources, transforming it into a suitable format, and loading it
into a target database or data warehouse. ETL processes are fundamental in data integration,
allowing businesses to consolidate data from different sources for analysis, reporting, and
decision-making
Step-by-Step Guide to Enhance the ETL Process with Data Aggregation and
Enrichment
Let's assume you're using a common ETL tool like Talend, Apache NiFi, or Pentaho Data
Integration (PDI). The steps will be similar across tools, with differences mainly in the user
interface.
4. Validation
APPLICATIONS:
1. Data Warehousing
3. Data Migration
4. Data Integration
AIM: Enhance the ETL (Extract, Transform, Load) process to not only load data from
multiple sources but also perform aggregations and enrich the dataset with additional
information.
ALGORITHMS:
Source Data Preparation:
Extract:
o Import data from the CSV file and SQL database.
Transform:
o Aggregation:
Aggregate sales data from the SQL database by month and product to
calculate TotalQuantitySold and TotalSaleAmount.
o Enrichment:
Enrich the production data by adding a ProductCategory based on
predefined rules or external data.
Load:
o Insert the transformed and aggregated data into the Production, Sales, and
MonthlySalesSummary tables.
Validation:
IMPLEMENTATION:
Extract Data:
CSV Extraction:
import pandas as pd
# Load CSV data into DataFrame
production_df = pd.read_csv('production_data.csv')
SQL Extraction
import pandas as pd
import sqlalchemy
# Connect to SQL database
engine = sqlalchemy.create_engine('mysql+pymysql://user:password@host/dbname')
sales_df = pd.read_sql('SELECT * FROM sales_data', engine)
Transform Data:
Aggregation:
Load Data:
Validation:
OUTPUT:
Sample Output
1. Production Table:
2. Sales Table:
3. MonthlySalesSummary Table:
RESULT: Thus to Enhance the ETL (Extract, Transform, Load) process to not only load
data from multiple sources but also perform aggregations and enrich the dataset with
additional information has been successfully executed
Ex.No.: 8
ORACLE DATABASE
Store and retrieve voluminous data using SanssouciDB / Oracle DB.
PROBLEM STATEMENT:
A large dataset in an educational institution where student records are maintained in two
different classes (class1 and class2). Due to administrative needs, there is a requirement to
combine these records and retrieve specific information based on various criteria such as age
or grade. The objective is to demonstrate efficient data management and retrieval techniques
in Oracle DB by working with voluminous data.
INTRODUCTION:
Oracle Database is a robust and widely used relational database management system
(RDBMS) known for its scalability, performance, and security features. It supports a wide
range of data management tasks, including storing, retrieving, and manipulating large
volumes of data. Oracle's SQL language and advanced features like PL/SQL, partitioning,
and indexing make it a popular choice for enterprise applications.
Ensure you have access to an Oracle Database instance. You can use Oracle SQL Developer
or SQL*Plus for executing SQL queries.
You will create two tables to simulate storing employee records separately for different
departments.
To simulate a large dataset, you'll insert a significant number of records into both tables.
You can apply various SQL queries to retrieve specific information from the combined
dataset.
APPICATIONS:
3. Data Warehousing
4. E-commerce
6. Healthcare
8. Telecommunications
AIM:
ALGORITHM:
Create Tables:
Insert Data:
Insert a large amount of sample employee data into these tables to simulate a real-
world scenario with voluminous data.
Display Sample Data:
Retrieve and display a subset of the data from both tables to verify that the data has
been correctly inserted.
Combine Data:
Use the SQL UNION operation to combine the data from both tables. This operation
eliminates duplicate records and provides a unified view of all employee data.
Retrieve and display the combined data, applying filters to demonstrate data retrieval
based on specific criteria such as age or salary.
Retrieve and display data for employees aged between 30 and 40.
Retrieve and display data for employees with a salary greater than 60,000.
IMPLEMENTATION:
SELECT * FROM (
SELECT * FROM employee_department1
UNION
SELECT * FROM employee_department2
) WHERE age
SELECT * FROM (
SELECT * FROM employee_department1
UNION
SELECT * FROM employee_department2
) WHERE salary > 60000;
OUTPUT:
All unique employee records from both departments are displayed after performing
the UNION operation. Example output:
A filtered set of combined data is displayed based on the specified criteria (e.g., age >
30 and salary > 50,000). Example output:
RESULT: Thus to demonstrate how to efficiently manage and retrieve a large dataset of
employee information stored in separate tables for different departments using Oracle DB
has been successfully executed
Ex.No.: 9
NO SQL
You are the database administrator for a manufacturing company that produces various
electronic components. The company wants to adopt a NoSQL database to handle its
dynamic and complex data requirements more efficiently, including inventory management,
employee information, and production tracking. Your task is to design a MongoDB database
that meets these requirements and perform various CRUD operations to demonstrate its
capabilities.
INTRODUCTION:
NoSQL (Not Only SQL) databases are designed to handle large volumes of unstructured,
semi-structured, or structured data with high scalability and flexibility. Unlike traditional
relational databases that use SQL, NoSQL databases support various data models like key-
value, document, column-family, and graph. They are particularly useful in scenarios where
data needs to be distributed across many servers, or when the data model changes frequently,
such as in real-time analytics, content management, and Internet of Things (IoT) applications.
Before you begin, ensure you have access to an Oracle NoSQL Database instance. You can
run Oracle NoSQL on-premises, or you can use Oracle NoSQL Cloud Service.
Let’s assume you have two datasets: one for supermarkets and another for genres of products
sold in those supermarkets.
You can insert records into these tables using Oracle NoSQL’s API. Below is an example in
Python:
Oracle Database supports integration with Oracle NoSQL Database, allowing you to expose
NoSQL data as relational tables. This can be achieved through Oracle SQL Access for
NoSQL.
Once the external tables are created, you can run SQL queries on the NoSQL data as if it
were in Oracle Database.
APPICATIONS:
6. Mobile Applications
AIM:
To leverage MongoDB to efficiently manage and analyze data related to inventory, employee
information, and production tracking.
ALGORITHM:
Database Design:
CRUD Operations:
Aggregation Pipelines:
Use aggregation to analyze and summarize data (e.g., total inventory value, employee
performance metrics).
IMPLEMENTATION:
Schema Design:
Products Collection:
{
"_id": ObjectId,
"productName": "string",
"category": "string",
"price": "number",
"stockQuantity": "number"
}
Employees Collection:
{
"_id": ObjectId,
"employeeName": "string",
"position": "string",
"hireDate": "ISODate",
"salary": "number"
}
ProductionRecords Collection:
{
"_id": ObjectId,
"productId": ObjectId,
"quantityProduced": "number",
"productionDate": "ISODate"
}
2. CRUD Operations
Create:
// Connect to MongoDB
const db = connect('mongodb://localhost:27017/manufacturing');
javascript
Copy code
// Find all products
db.Products.find({}).toArray();
// Delete a product
db.Products.deleteOne({ productName: "Smartphone" });
// Delete an employee
db.Employees.deleteOne({ employeeName: "Alice Smith" });
3. Aggregation Pipelines
db.ProductionRecords.aggregate([
{
$lookup: {
from: "Products",
localField: "productId",
foreignField: "_id",
as: "productDetails"
}
},
{ $unwind: "$productDetails" },
{
$group: {
_id: "$productDetails.category",
totalQuantityProduced: { $sum: "$quantityProduced" }
}
}
]).toArray();
4. Indexing
Create Indexes:
OUTPUT:
RESULT: Thus To leverage MongoDB to efficiently manage and analyze data related
to inventory, employee information, and production tracking has been successfully executed.
Ex.No.: 10
Build Web applications using Java servlet API for storing data in databases that can be
queried using variant of SQL.
Problem Statement
You are tasked with developing a simple web application that manages user information for a
company. The application should provide an interface for users to add, view, update, and
delete user records. The application should be built using PHP for server-side scripting and
MySQL for the database.
INTRODUCTION:
An integrated database refers to a system where data is stored in a manner that allows
seamless integration with different software applications, particularly web applications. It
often involves using relational databases that can be queried using SQL (Structured Query
Language) or its variants. The integration allows developers to create, retrieve, update, and
delete (CRUD) operations on data through web applications, ensuring that the data remains
consistent and accessible.
In the context of web applications, Java Servlet API is commonly used to build dynamic web
applications that interact with databases. Java Servlets handle HTTP requests and responses,
while JDBC (Java Database Connectivity) allows Java applications to interact with relational
databases.
STEP-BY-STEP-PROCESS:
Before you start, ensure you have the following tools and software installed:
First, create a database that your web application will interact with.
1. Open Eclipse and go to File > New > Dynamic Web Project.
2. Enter the project name (e.g., UserManagementApp), select the target runtime (e.g.,
Apache Tomcat), and click Finish.
1. Download the JDBC driver for your database (e.g., MySQL Connector/J for MySQL).
2. Right-click on your project, go to Build Path > Configure Build Path, and add the
JDBC driver JAR file to the project’s classpath.
1. Deploy the Web Application: Right-click on the project and select Run As > Run on
Server.
2. Access the Application: Open a web browser and go to
http://localhost:8080/UserManagementApp/register.jsp to register a user, or
http://localhost:8080/UserManagementApp/login.jsp to log in.
APPLICATIONS:
1. E-commerce Platforms
5. Educational Platforms
AIM:
ALGORITHM:
Setup Environment
Install a local server environment like XAMPP or WAMP that includes PHP and
MySQL.
Create a MySQL database and table for storing employee information.
Establish a connection to the MySQL database using PHP’s mysqli or PDO extension.
Create functions for CRUD operations.
Design HTML forms for adding, viewing, updating, and deleting employee records.
Use PHP to handle form submissions and display data.
IMPLEMENTATION:
1. Install XAMPP/WAMP:
o Download and install XAMPP (Windows, Linux) or WAMP (Windows) from
their official sites.
o Start Apache and MySQL services from the control panel.
2. Create Database and Table:
sql
Copy code
CREATE DATABASE company_db;
USE company_db;
db_connect.php
php
Copy code
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "company_db";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
3. Build User Interface
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Management</title>
</head>
<body>
<h1>Employee Management System</h1>
<h2>Add Employee</h2>
<form action="add_employee.php" method="post">
Name: <input type="text" name="name" required><br>
Position: <input type="text" name="position"><br>
Department: <input type="text" name="department"><br>
Email: <input type="email" name="email" required><br>
<input type="submit" value="Add Employee">
</form>
<h2>View Employees</h2>
<?php
$sql = "SELECT * FROM employees";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table
border='1'><tr><th>ID</th><th>Name</th><th>Position</th><th>Department</
th><th>Email</th><th>Actions</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr><td>{$row['id']}</td><td>{$row['name']}</td><td>{$row['position']}</
td><td>{$row['department']}</td><td>{$row['email']}</td>";
echo "<td><a href='update_employee.php?id={$row['id']}'>Update</a> | <a
href='delete_employee.php?id={$row['id']}'>Delete</a></td></tr>";
}
echo "</table>";
} else {
echo "No employees found.";
}
?>
</body>
</html>
add_employee.php
<?php
include 'db_connect.php';
$name = $conn->real_escape_string($_POST['name']);
$position = $conn->real_escape_string($_POST['position']);
$department = $conn->real_escape_string($_POST['department']);
$email = $conn->real_escape_string($_POST['email']);
$sql = "INSERT INTO employees (name, position, department, email) VALUES ('$name',
'$position', '$department', '$email')";
$conn->close();
?>
update_employee.php
<?php
include 'db_connect.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$id = (int)$_POST['id'];
$name = $conn->real_escape_string($_POST['name']);
$position = $conn->real_escape_string($_POST['position']);
$department = $conn->real_escape_string($_POST['department']);
$email = $conn->real_escape_string($_POST['email']);
$conn->close();
} else {
$id = (int)$_GET['id'];
$sql = "SELECT * FROM employees WHERE id=$id";
$result = $conn->query($sql);
$employee = $result->fetch_assoc();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Update Employee</title>
</head>
<body>
<h1>Update Employee</h1>
<form action="update_employee.php" method="post">
<input type="hidden" name="id" value="<?php echo $employee['id']; ?>">
Name: <input type="text" name="name" value="<?php echo $employee['name']; ?>"
required><br>
Position: <input type="text" name="position" value="<?php echo $employee['position'];
?>"><br>
Department: <input type="text" name="department" value="<?php echo
$employee['department']; ?>"><br>
Email: <input type="email" name="email" value="<?php echo $employee['email']; ?>"
required><br>
<input type="submit" value="Update Employee">
</form>
</body>
</html>
delete_employee.php
<?php
include 'db_connect.php';
$id = (int)$_GET['id'];
$conn->close();
?>
OUTPUT:
Adding an Employee
After filling out the form and submitting, you would see:
Viewing Employees
You would see a table with employee details and action links:
Updating an Employee
Deleting an Employee
Security Measures
SQL Injection Prevention: Use prepared statements to prevent SQL injection. For
instance, modify add_employee.php as follows: