0% found this document useful (0 votes)
11 views4 pages

Static Hashing Implementation in SQL Server

The document is a lab manual for implementing Static Hashing in SQL Server, aimed at teaching students how to create a table with a hashed bucket column, insert and search for records, and optimize searching with an index. It explains the concept of Static Hashing, provides a formula for bucket allocation, and outlines a step-by-step procedure for completing exercises related to student records. The lab includes SQL commands for creating tables, inserting data, querying, and deleting records using hashing techniques.

Uploaded by

ezamunir57
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Static Hashing Implementation in SQL Server

The document is a lab manual for implementing Static Hashing in SQL Server, aimed at teaching students how to create a table with a hashed bucket column, insert and search for records, and optimize searching with an index. It explains the concept of Static Hashing, provides a formula for bucket allocation, and outlines a step-by-step procedure for completing exercises related to student records. The lab includes SQL commands for creating tables, inserting data, querying, and deleting records using hashing techniques.

Uploaded by

ezamunir57
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Advancd Database

Management System

3/26/2025

Submitted To:Mam Habiba

Submitted By: Eza Munir


Section: A
Lab Manual
Lab Title: Implementing Static Hashing in SQL Server
Objective:
The objective of this lab is to understand and implement Static Hashing in SQL Server. By the
end of this lab, students will be able to:
• Create a table with a Hashed Bucket Column.
• Insert data into the table.
• Search for specific records using hashing techniques.
• Create an index to optimize searching.
• Delete a record using hashed bucket method.

What is Static Hashing?


Static Hashing is a technique used in database indexing where a hash function is applied to
distribute data into fixed number of buckets. The bucket allocation is determined using:
h(k) = k mod N
where: k is the key value (e.g., StudentID)
N is the total number of buckets
This method allows fast data retrieval and efficient search operations.

Lab Procedure:
Create database onlinelab;
use onlinelab;
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
HashBucket INT GENERATED ALWAYS AS (StudentID % 10) VIRTUAL
);

Student Task:
Now, complete the following exercises on your own:

1
Insert 5 more student records into the Students table.
Write a query to find a student with StudentID = 105 using hashing.
Create an index on StudentID for additional optimization.
Delete a record where StudentID = 106 using hashing.

1. Insert 5 more student records into the Students table.


INSERT INTO Students (StudentID, Name, Age)
VALUES
(105, 'Omar', 22);
INSERT INTO Students (StudentID, Name, Age)
VALUES
(106, 'Hassan', 20);
INSERT INTO Students (StudentID, Name, Age)
VALUES
(107, 'Aisha', 23);
INSERT INTO Students (StudentID, Name, Age)
VALUES
(108, 'Noor', 24);
INSERT INTO Students (StudentID, Name, Age)
VALUES
(109, 'Fatima', 21);

2. Write a query to find a student with StudentID = 105 using hashing.


SELECT * FROM Students WHERE HashBucket = (105 % 10) AND StudentID = 105;

Figure:1.1

2
3. Create an index on StudentID for additional optimization.
CREATE INDEX idx_studentid ON Students (StudentID);
4. Delete a record where StudentID = 106 using hashing.
DELETE FROM Students WHERE HashBucket = (106 % 10) AND StudentID = 106;
SELECT * FROM Students WHERE StudentID = 106;

Figure:1.2

SELECT * FROM Students;

Figure:1.3

You might also like