- A file is a collection of records where a record consists of one or more fields. Each contains the same sequence of fields.
- Each field is normally of fixed length.
- A sample file with four records is shown below:
- There are four records
- Also, There are four fields (Name, Roll No., Year, Marks)
- Records can be uniquely identified on the field ‘Roll No.’ Therefore, Roll No. is the key field.
- Moreover, A database is a collection of files.
- Commonly, used file organizations are :
- Sequential files
- Relative files
- Direct files
- Indexed Sequential files
- Index files
- Primitive Operations on a File :
It is the most common type of file. In this type of file:
- A fixed format is used for the record.
- All records are of the same length.
- Also, The position of each field in record and length of the field is fixed.
- So, Records are physically ordered on the value of one of the fields – called the ordering field.
Some blocks of an ordered (sequential) file of students records with Roll no. as the ordering field
Advantages of the sequential file over unordered files :
- Reading of records in order of the ordering key is extremely efficient.
- Finding the next record in order of the ordering key usually, does not require additional block access. Moreover, Next record may found in the same block.
- Moreover, Searching operation on ordering key is must faster. Binary search can utilize. Also, A binary search will require log2b block accesses where b is the total number of blocks in the file.
Disadvantages of sequential file
- The sequential file does not give any advantage when the search operation is to carry out in non- ordering field.
- Inserting a record is an expensive operation. Insertion of a new record requires the finding of a place of insertion and then all records ahead of it must move to create space for the record to insert. Moreover, This could be very expensive for large files.
- Moreover, Deleting a record is an expensive operation. So, Deletion too requires movement of records.
- Modification of field value of ordering key could time-consuming. Also, Modifying the ordering field means the record can change its position. This requires deletion of the old record followed by insertion of the modified record.