0% found this document useful (0 votes)
5 views

Unit v Dbms Question and Answer

The document provides an overview of file organization and types of indexes used in databases, including primary and secondary indexes, dense and sparse indexes, and ordered versus unordered records. It explains the characteristics and operations of various file organizations such as sequential, heap, and indexed file organization, highlighting their advantages and disadvantages. Additionally, it details file operations including opening, locating, reading, writing, and closing files.

Uploaded by

meharkaran09
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Unit v Dbms Question and Answer

The document provides an overview of file organization and types of indexes used in databases, including primary and secondary indexes, dense and sparse indexes, and ordered versus unordered records. It explains the characteristics and operations of various file organizations such as sequential, heap, and indexed file organization, highlighting their advantages and disadvantages. Additionally, it details file operations including opening, locating, reading, writing, and closing files.

Uploaded by

meharkaran09
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

UNIT V

What is a File?
A file is named a collection of related information that is recorded on secondary storage such as magnetic disks, magnetic
tapes, and optical disks.

Q1 DIFFERENTIATE PRIMARY INDEX AND SECONDARY INDEX.

The main differences between primary and secondary indexes are:


• Creation: Primary indexes are automatically created with the primary key, while secondary indexes are created after the table
is created.
• Organization: Primary indexes organize data in a sorted order based on the primary key. Secondary indexes are based on non-
primary key columns.
• Density: Primary indexes are sparse, while secondary indexes are dense.
• Number of indexes: There can be at most one primary index for a file, but there can be more than one secondary index for the
same file.
• Storage space: Primary indexes need less storage space, while secondary indexes need more storage space.
• Search time: Secondary indexes have a longer search time.
• Purpose: Primary indexes speed up data retrieval by pointing directly to the physical location of data on disk. Secondary
indexes improve the performance of queries that do not use the primary key for search criteria
Q2 DIFFERNTIATE BETWEEN SPARSE INDEX AND DENSE INDEX .
Difference Between Dense Index and Sparse Index

Dense index Sparse index

The index size is larger in dense index. In sparse index, the index size is smaller.

Time to locate data in index table is less. Time to locate data in index table is more.

There is more overhead for insertions and Sparse indexing have less overhead for
deletions in dense index. insertions and deletions.

Records in dense index need not to be In case of sparse index, records need to be
clustered. clustered.

Computing time in RAM (Random access In sparse index, computing time in RAM is
memory) is less with dense index. more.

Data pointers in dense index point to each In sparse index, data pointers point to
record in the data file. fewer records in data file.
Dense index Sparse index

In sparse index, search performance may


Search performance is generally faster in
require additional steps, which will result
dense index.
in slowing down the process.

DENSE INDEX
SPARSE INDEX
Q3 EXPLAIN FILE OF ORDERED RECORDS AND UNORDERED RECORDS .
FILE OF ORDERED RECORDS
1 ALSO CALLED AS SEQUENTIAL FILE
2 RECORDS ARE SORTED BY VALUES OF ORDERING FIELD
3 INSERTION OF NEW RECORD IS EXPENSIVE ,RECORDS MUST BE INSERTED IN CORRECT ORDER.
4 BINARY SEARCH CAN BE USED TO SEARCH FOR RECORD ON ITS ORDERING FIELD VALUE .
5 READING RECORDS IN ORDER OF ORDERING FIELD IS EFFICIENT
6 EASIER TO SEARCH .
7 Insertion and deletion of records is slower in ordered files
8 Ordered files have a specific order
9 Insertion and deletion: Insertion and deletion of records is slower in ordered files
FILE OF UNORDERED RECORDS
1 RECORDS ARE PLACED IN FILE IN ORDER IN WHICH THEY ARRIVE .
2 LINEAR SEARCH IS USED TO SEARCH RECORDS .
3 HEAP FILE FOLLOWS THIS CONCEPT.
4 UNORDERED FILES CAN BE ACCESSED IN ANY ORDER.
5 TOUGH TO SEARCH
6 Insertion and deletion of records is FAST in ordered files
7 UN Ordered files DO NOT have a specific order
8 Insertion and deletion: Insertion and deletion of records is FAST in ordered files
Q4 EXPLAIN FILE OPERATIONS .

Open − A file can be opened in one of the two modes, read mode or write mode.
Locate − Every file has a file pointer, which tells the current position where the data is to be
read or written.
Read − By default, when files are opened in read mode, the file pointer points to the
beginning of the file.
Write − User can select to open a file in write mode, which enables them to edit its
contents.
Close - CLOSE THE FILE

Explain File Organization.

What is File Organization?


File Organization refers to the logical relationships among various records that constitute the
file, particularly with respect to the means of identification and access to any specific record.
In simple terms, Storing the files in a certain order is called File Organization.
The Objective of File Organization
• It helps in the faster selection of records i.e. it makes the process faster.
• Different Operations like inserting, deleting, and updating different records are faster
and easier.
• It prevents us from inserting duplicate records via various operations.
• It helps in storing the records or the data very efficiently at a minimal cost.
Types of file organization

Sequential File Organization


The easiest method for file Organization is the Sequential method. In this method, the file is
stored one after another in a sequential manner.
Advantages of Sequential File Organization
• Fast and efficient method for huge amounts of data.
• Simple design.
• Files can be easily stored in magnetic tapes i.e. cheaper storage mechanism.
Disadvantages of Sequential File Organization
• Time wastage as we cannot jump on a particular record that is required, but we have to
move in a sequential manner which takes our time.
• The sorted file method is inefficient as it takes time and space for sorting records.

Heap File Organization


Heap File Organization works with data blocks. In this method, records are inserted at the
end of the file, into the data blocks. No Sorting or Ordering is required in this method. If a
data block is full, the new record is stored in some other block, Here the other data block
need not be the very next data block, but it can be any block in the memory. It is the
responsibility of DBMS to store and manage the new records.
Advantages of Heap File Organization
• Fetching and retrieving records is faster than sequential records but only in the case of
small databases.
• When there is a huge number of data that needs to be loaded into the database at a
time, then this method of file Organization is best suited.
Disadvantages of Heap File Organization
• The problem of unused memory blocks.
• Inefficient for larger databases.

Indexed file organization is a method of storing records in a computer file using a record key
to uniquely identify each record. The record key is a field within each record that determines
the order in which the records are accessed
characteristics of indexed file organization
• Record keys: Each record has a unique record key, such as an employee number or
invoice number.
• Indexes: Each key is associated with an index that provides a logical path to the record.
• Access modes: Indexed files can be accessed sequentially, randomly, or dynamically

You might also like