4
1/16/2017 File management in SQL Database / BS-IT 2nd Submitted to : Ma’m Mehwashma Amir Afrasiyab Haider 16-ARID-02

File organization in database

Embed Size (px)

Citation preview

Page 1: File organization in database

1/16/2017

File management in SQL

Database / BS-IT 2nd

Submitted to : Ma’m Mehwashma Amir

Afrasiyab Haider16-ARID-02

Page 2: File organization in database

1 File management in SQL

Afrasiyab Haider|16-ARID-02

File Organization in database:

In a database we have lots of data. Each data is grouped into related groups called tables. Each table will have lots of related records. Any user will see these records in the form of tables in the screen. But these records are stored as files in the memory. Usually one file will contain all the records of a table. If they are not stored as tables, there and our SQL queries will not work. We need some accessing methods. To access these files, we need to store them in certain order so that it will be easy to fetch the records. It is same as indexes in the books, or catalogues in the library, which helps us to find required topics or books respectively. Storing the files in certain order is called file organization. 

 The main objective of file organization is

Optimal selection of records i.e.; records should be accessed as fast as possible. Any insert, update or delete transaction on records should be easy, quick and should not

harm other records. No duplicate records should be induced as a result of insert, update or delete Records should be stored efficiently so that cost of storage is minimal.

Types of file organization:

Sequential File Organization Indexed File Organization Hashed File Organization

Sequential file organization:

It is one of the simple methods of file organization. Here each file/records are stored one after the other in a sequential manner. This can be achieved in two ways:

1. Records are stored one after the other as they are inserted into the tables. This method is called pile file method. When a new record is inserted, it is placed at the end of the file. In the case of any modification or deletion of record, the record will be searched in the memory blocks. Once it is found, it will be marked for deleting and new block of record is entered.

2. A sequential file contains records organized by the order in which they were entered. The order of the records is fixed.

3. Records in sequential files can be read or written only sequentially.

4. After you place a record into a sequential file, you cannot shorten, lengthen, or delete the record. However, you can update (REWRITE) a record if the length does not change. New records are added at the end of the file.

Page 3: File organization in database

2 File management in SQL

Afrasiyab Haider|16-ARID-02

5. If the order in which you keep records in a file is not important, sequential organization is a good choice whether there are many records or only a few. Sequential output is also useful for printing reports.

Indexed File Organization:

1. An indexed file contains records ordered by a record key. A record key uniquely identifies a record and determines the sequence in which it is accessed with respect to other records.

2. Each record contains a field that contains the record key. A record key for a record might be, for example, an employee number or an invoice number.

3. An indexed file can also use alternate indexes, that is, record keys that let you access the file using a different logical arrangement of the records. For example, you could access a file through employee department rather than through employee number.

4. The possible record transmission (access) modes for indexed files are sequential, random, or dynamic. When indexed files are read or written sequentially, the sequence is that of the key values.

5. EBCDIC consideration: As with any change in the collating sequence, if your indexed file is a local EBCDIC file, the EBCDIC keys will not be recognized as such outside of your COBOL program. For example, an external sort program, unless it also has support for EBCDIC, will not sort records in the order that you might expect.

Hashed File Organization:

1. Records need not be sorted after any of the transaction. Hence the effort of sorting is reduced in this method.

2. Since block address is known by hash function, accessing any record is very faster. Similarly updating or deleting a record is also very quick.

3. This method can handle multiple transactions as each record is independent of other. i.e.; since there is no dependency on storage location for each record, multiple records can be accessed at the same time.

4. It is suitable for online transaction systems like online banking, ticket booking system etc.