Week 9-10 Managing Control and Redo Log File
Week 9-10 Managing Control and Redo Log File
• Inverted file –
you can have more than one index, each with a different key.
Inverted file
• A file that reorganizes the structure of an existing data file to enable a rapid search
to be made for all records having one field falling within set limits.
• For example, a file used by an estate agent might store records on each house for
sale, using a reference number as the key field for sorting. One field in each
record would be the asking price of the house. To speed up the process of drawing
up lists of houses falling within certain price ranges, an inverted file might be
created in which the records are rearranged according to price. Each record would
consist of an asking price, followed by the reference numbers of all the houses
offered for sale at this approximate price.
Figure 13-6 Logical view of an indexed file
File Organization and Indexing
Index:
An alphabetical list of names,
subjects, etc. with reference to their
page(s) number
7
File Organization and Indexing
8
Log files
• The transaction log is an integral part of SQL Server. Every database
has a transaction log that is stored within the log file that is separate
from the data file. A transaction log basically records all database
modifications. When a user issues an INSERT, for example, it is logged
in the transaction log. This enables the database to roll back or
restore the transaction if a failure were to occur and prevents data
corruption.
• For example, let’s say Ahmad is using an application and inserts 2000
rows of data.
• While SQL Server is processing this data let’s say someone pulls the
plug on the server.
• Because the INSERT statement was writing to the transaction log and
it knows a failure occurred it will roll back the statement.
• this wasn’t put in place, could you imagine having to sift through the
data to see how many rows it inserted and then change the code to
insert the remaining rows? Or even better, what if the application
inserted random columns in no order and you had to determine what
data was inserted and what data was left out? This could take forever!
• Log entries are sequential in nature. The transaction log is split up into
small chunks called virtual log files, which we will discuss in a later
section. When a virtual log file is full, transactions automatically move
to the next virtual log file. As long as the log records at the beginning
of the transaction log have been truncated when logging reaches the
end of the log, it will circle back around to the start and will overwrite
what was there before: