Total Pageviews

Monday, August 31, 2026

📁 FILE OPERATIONS IN DBMS

📁 FILE OPERATIONS IN DBMS
Create • Open • Read • Write • Search • Insert • Update • Delete • Close
📘 What is a File in DBMS?

A file is a collection of related records stored on secondary storage such as a hard disk or SSD.

For example, a STUDENT file may contain:
Student_ID | Name | Course | Marks
The DBMS performs several operations on these records.

Main File Operations:
✔ Create
✔ Open
✔ Read
✔ Write
✔ Search
✔ Insert
✔ Update
✔ Delete
✔ Close

📁 File Operations

File operations are activities performed by the DBMS to store, retrieve, modify and manage records in a database file.

Basic Flow

CREATE FILE ↓ OPEN FILE ↓ READ / WRITE ↓ SEARCH / INSERT / UPDATE / DELETE ↓ CLOSE FILE
The DBMS hides most physical storage details from the user and provides a logical way to work with data.

📋 Record and Field

A field is a single attribute or data item. A record is a collection of related fields representing one entity.

Example

Student_ID Name Course Marks
101 Rahul BCA 85
102 Anita BCA 91
One row = Record
One column = Field / Attribute

➕ CREATE Operation

The CREATE operation establishes a new database object, such as a table or file structure, depending on the DBMS and storage system.

Example

CREATE TABLE STUDENT
(Student_ID, Name, Course, Marks)

Step-by-Step

1
User requests creation of a new structure.
2
DBMS checks the definition.
3
Storage metadata is created.
4
The new structure becomes available for data operations.

📂 OPEN Operation

Opening a file means making the required file/storage structure available for subsequent operations.
OPEN(STUDENT)
1
DBMS identifies the required file or relation.
2
It checks metadata and access permissions.
3
Required storage structures are made available.
The file is now ready for reading or modification.

📖 READ Operation

READ retrieves data from storage into memory so that the DBMS can process or return it.

Example

READ(Student_ID = 101)
1
DBMS receives a request for Student 101.
2
It locates the required record.
3
The record is read from storage.
4
The data is returned for processing.
Result:
101 | Rahul | BCA | 85

✍️ WRITE Operation

WRITE stores a new or modified block/record into storage.

Example

WRITE
103 | Suman | BCA | 88
1
Prepare the record.
2
Locate an appropriate storage location.
3
Write the record to storage.
Record successfully stored.

➕ INSERT Operation

INSERT adds a new record to a table or file.
INSERT: 104 | Arjun | BCA | 79

Step-by-Step

1
New record is prepared.
2
DBMS checks constraints.
3
DBMS finds a suitable storage location.
4
Record is stored.
New record becomes part of the database.

🔄 UPDATE Operation

UPDATE changes one or more values of an existing record.

Before

101 | Rahul | BCA | 85

Operation

UPDATE Marks 85 → 90

After

101 | Rahul | BCA | 90
1
Find the required record.
2
Check the requested modification.
3
Change the value.
4
Write the modified record back to storage.

🗑️ DELETE Operation

DELETE removes a selected record from the database.

Before

102 | Anita | BCA | 91

Operation

DELETE WHERE Student_ID = 102
1
Search for Student_ID 102.
2
Locate the record.
3
Remove the record logically/physically according to the DBMS storage method.
Student 102 is no longer part of the active relation.

🔒 CLOSE Operation

CLOSE ends the current file/storage access session and releases resources associated with the operation.
READ / WRITE ↓ FINISH OPERATIONS ↓ CLOSE
Closing helps ensure that resources such as file handles, buffers and related system resources are properly managed.

🗃️ File Organization

File organization describes how records are physically arranged on secondary storage.
Organization Main Idea Useful For
Sequential Records stored in an ordered sequence Sequential processing
Heap Records stored without a required ordering Fast insertion
Hash Hash function determines storage location Equality search
Indexed Index helps locate records Fast searching

1️⃣ Sequential File Organization

Records are stored one after another, usually according to some ordering such as Student_ID.
101 → 102 → 103 → 104 → 105

Example Search

Suppose we search for Student_ID = 104.

1
Check 101.
2
Check 102.
3
Check 103.
4
Find 104.
Sequential search may require examining many records.

#️⃣ Hash File Organization

Hash organization uses a hash function to determine the storage location of a record.
Address = h(Key)

Example:
h(Student_ID) = Student_ID mod 10

Numerical Example

1
Student_ID = 103
2
Hash function = 103 mod 10
3
103 mod 10 = 3
Record 103 is mapped to hash bucket 3.
Different keys may produce the same bucket. This is called a collision.

📑 Indexed File Organization

An index is an additional data structure that helps the DBMS locate records more efficiently.

Example

Student_ID Record Location
101 Block 1
102 Block 1
103 Block 2
104 Block 3

Instead of scanning every record, the DBMS can use the index to identify a relevant storage location.

Index → Faster data retrieval
Trade-off → Additional storage and maintenance cost

🏫 Complete Student File Example

Initial File

ID Name Course Marks
101 Rahul BCA 85
102 Anita BCA 91
103 Suman BCA 88

1. INSERT

INSERT 104 | Arjun | BCA | 79

2. UPDATE

UPDATE 103
Marks: 88 → 92

3. SEARCH

SEARCH Student_ID = 102
Result → Anita

4. DELETE

DELETE Student_ID = 101
The file has now been modified through a sequence of INSERT, UPDATE, SEARCH and DELETE operations.

🎯 Complete File Operation Sequence

1
CREATE
Create the required database structure.
2
OPEN
Make the required storage structure available.
3
READ
Retrieve existing data.
4
SEARCH
Locate a particular record.
5
INSERT
Add a new record.
6
UPDATE
Modify an existing record.
7
DELETE
Remove an unwanted record.
8
CLOSE
Finish the file/storage access operation and release resources.
CREATE → OPEN → READ / WRITE → SEARCH → INSERT / UPDATE / DELETE → CLOSE

⚖️ File Organization Comparison

Method Advantage Disadvantage
Sequential Simple and good for sequential processing Searching may be slow
Heap Fast insertion Searching may require scanning
Hash Very efficient equality search on average Collision handling required
Indexed Fast retrieval Extra storage and index maintenance

Easy Memory Trick

SEQUENTIAL → ORDER

HEAP → SIMPLE STORAGE

HASH → KEY → ADDRESS

INDEX → SEARCH FASTER

❓ Important Questions & Answers

Q1. What is a file in DBMS?
A file is a collection of related records stored on secondary storage and managed by the database/storage system.
Q2. What is a record?
A record is a collection of related fields representing one entity or occurrence.
Q3. What is a field?
A field is a single data item or attribute within a record.
Q4. What is file organization?
File organization is the method used to arrange records on secondary storage.
Q5. What is sequential file organization?
It stores records sequentially, generally according to a specified ordering.
Q6. What is hash file organization?
Hash file organization uses a hash function to map a search key to a storage bucket or location.
Q7. What is an index?
An index is an auxiliary data structure that helps the DBMS locate records more efficiently.
Q8. What is INSERT?
INSERT adds a new record to a relation or file.
Q9. What is UPDATE?
UPDATE modifies one or more values in an existing record.
Q10. What is DELETE?
DELETE removes records that satisfy a specified condition.
Q11. What is a hash collision?
A hash collision occurs when two different keys are mapped to the same hash bucket or location.
Q12. Which file organization is useful for equality search?
Hash organization is particularly useful for equality searches, while indexed organizations can support a wider range of searches depending on the index type.

No comments:

Post a Comment