Dbms Lab Manual
Dbms Lab Manual
Procedure:
Create Table:
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL,
Email VARCHAR(100) UNIQUE,
DepartmentID INT,
CONSTRAINT FK_Department FOREIGN KEY (DepartmentID) REFERENCES
Departments(DepartmentID)
);
Insert Data:
INSERT INTO Employees (EmployeeID, FirstName, LastName, Email, DepartmentID)
VALUES (1, 'John', 'Doe', '[email protected]', 101),
(2, 'Jane', 'Smith', '[email protected]', 102);
Update Data:
UPDATE Employees
SET DepartmentID = 103
WHERE EmployeeID = 2;
Delete Data:
DELETE FROM Employees
WHERE EmployeeID = 1;
Result: The Employees table is created with specified constraints (PRIMARY KEY,
NOT NULL, UNIQUE, FOREIGN KEY). Data can be inserted, updated, and deleted using
appropriate commands, ensuring data integrity and consistency.
2. Create a Set of Tables, Add Foreign Key Constraints, and
Incorporate Referential Integrity:
Aim: To design and link multiple tables using foreign key constraints for maintaining
relational integrity.
Procedure:
Create Tables:
Define multiple tables (CREATE TABLE ...) with primary keys.
Add Foreign Key Constraints:
ALTER TABLE Employees
ADD CONSTRAINT FK_Department FOREIGN KEY (DepartmentID) REFERENCES
Departments(DepartmentID);
Ensure Referential Integrity:
Establish relationships between tables to maintain consistency across related data.
Result: Data subsets are retrieved based on specified conditions (WHERE clauses), and
aggregate functions (COUNT, AVG, etc.) provide calculated results from the queried data.
4. Query Database Tables and Explore Subqueries and Simple
Join Operations:
Aim: : To combine data from multiple tables and use nested queries for complex data
retrieval.
Procedure:
Subqueries:
SELECT *
FROM Employees
WHERE DepartmentID IN (SELECT DepartmentID FROM Departments WHERE Location
= 'New York');
Simple Joins:
SELECT e.*, d.DepartmentName
FROM Employees e
INNER JOIN Departments d ON e.DepartmentID = d.DepartmentID;
Result: Subqueries and simple join operations successfully retrieve and combine data
from related tables (Employees and Departments), facilitating complex data analysis and
reporting.
Procedure:
Natural Join:
SELECT *
FROM Employees
NATURAL JOIN Departments;
Equi-Join:
SELECT e.*, d.DepartmentName
FROM Employees e
JOIN Departments d ON e.DepartmentID = d.DepartmentID;
Outer Join:
SELECT e.*, d.DepartmentName
FROM Employees e
LEFT JOIN Departments d ON e.DepartmentID = d.DepartmentID;
Result: Various types of joins (NATURAL JOIN, INNER JOIN, LEFT OUTER JOIN)
are used to fetch data based on specified matching conditions, providing comprehensive data
retrieval capabilities.
Aim: To create custom functions and procedures for performing complex calculations and
data operations.
Procedure:
User-Defined Function:
CREATE FUNCTION CalculateBonus (@Salary DECIMAL)
RETURNS DECIMAL
AS
BEGIN
DECLARE @Bonus DECIMAL;
SET @Bonus = @Salary * 0.1; -- 10% bonus
RETURN @Bonus;
END;
Stored Procedure:
CREATE PROCEDURE GetEmployeeDetails (@EmployeeID INT)
AS
BEGIN
SELECT * FROM Employees WHERE EmployeeID = @EmployeeID;
END;
Procedure:
Begin a Transaction:
BEGIN TRANSACTION;
Execute DCL Commands (e.g., Grant Access):
GRANT SELECT, INSERT ON Employees TO User1;
Commit or Rollback Transaction:
COMMIT;
-- or
ROLLBACK;
Procedure:
Create View:
CREATE VIEW EmployeesSummary
AS
SELECT EmployeeID, FirstName, LastName, DepartmentID
FROM Employees
WHERE IsActive = 1;
Create Index:
CREATE INDEX idx_DepartmentID ON Employees (DepartmentID);
Procedure:
Create XML Collection:
CREATE XML SCHEMA COLLECTION EmployeeSchema AS '
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Employee">
<xs:complexType>
<xs:sequence>
<xs:element name="EmployeeID" type="xs:int"/>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="Email" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>';
SELECT EmployeeData
FROM EmployeeXMLData
WHERE EmployeeData.validate(EmployeeSchema) = 1;
Result: XML data (EmployeeXMLData) is stored in the database, validated against the
defined schema (EmployeeSchema), ensuring its structural integrity and adherence to
specified XML standards.
11. Create Document, Column, and Graph-Based Data Using No
Database Tools:
Aim: : To utilize No databases for handling diverse data models efficiently, including
document, column-family, and graph-based data.
Procedure:
Document Store (e.g., MongoDB):
o Create collections for storing flexible JSON-like documents.
o Perform CRUD operations using MongoDB's BSON query language.
Column-Family Store (e.g., Cassandra):
o Define column families to store data in rows and columns.
o Use CQL (Cassandra Query Language) for querying and managing data.
Graph Database (e.g., Neo4j):
o Model data as nodes (entities) and relationships (edges).
o Execute Cypher queries to traverse and analyze graph structures.
Procedure:
Design GUI Components:
o Create forms, buttons, and input fields for data entry and display.
o Include navigation controls for querying and updating database content.
Integrate Database Features:
o Implement backend logic to execute queries, triggers, and transactions.
o Connect to No databases and handle document, column, and graph-based data.
Ensure Data Security and Integrity:
o Implement user authentication and authorization mechanisms.
o Validate user inputs and sanitize data to prevent security vulnerabilities.
Result: A functional GUI-based database application is developed, providing users with
an intuitive interface to interact with and manage complex database operations effectively.
Procedure:
Select a Real-Life Scenario:
o Choose an application domain (e.g., e-commerce, healthcare, logistics).
o Identify specific challenges related to data management and analysis.
Design and Implement Database Solution:
o Define database schema and relationships based on application requirements.
o Implement transactional processes, triggers, views, and indexes to optimize
performance.
Document Implementation Process:
o Record challenges faced, decisions made, and solutions implemented.
o Evaluate the effectiveness of the database solution in addressing business
needs.