Microsoft SQL Server 7.0 System Administration Training Kit

[Previous] [Next]

When you create a database, you set up the data storage structure. This structure includes at least one data file and one transaction log file. Before creating a database, it is important to understand two concepts: how SQL Server 7 stores data and the function of the transaction log file.

After this lesson, you will be able to

Estimated lesson time: 15 minutes

How Data Is Stored

An understanding of how SQL Server stores data will give you insight into capacity planning, data integrity, and performance. Figure 5.1 shows how a database allocates space.

Figure 5.1 Database storage allocation

SQL Server Database Files

SQL Server 7 introduces a new architecture for databases. Database devices, used in previous versions, are no longer needed as storage units for a database. Instead, databases are stored in their own files. The following section introduces these files, which make up a database.

Database File Types

There are three types of database files:

Database File Considerations

Before creating a database, you must consider a number of issues. To effectively manage resources that the database will use, you must understand how SQL Server stores information. The following list summarizes how SQL Server allocates space to a database and database objects.

NOTE


SQL Server 7 differs significantly from SQL Server 6.5 with regard to data storage. SQL Server 6.5 uses 2-KB pages, thereby limiting a single row to 1962 bytes. Many other capacities have been increased in SQL Server 7; for more information, search for "maximum capacity specifications" in Books Online.

How the Transaction Log Works

The transaction log records data modifications—INSERT, UPDATE, and DELETE statements—as they are executed.

The logging process, shown in Figure 5.2, occurs as follows:

  1. The application sends a data modification.
  2. The affected data pages are loaded from the data file into memory (called the data cache) if they are not already in the data cache from a previous query.
  3. Each data modification statement is recorded as it is made in what is called a write-ahead log. The change is always recorded in the log and written to the log file before that change is made in the database.
  4. Once the data pages reside in the data cache and the log pages are recorded on the disk in the transaction log file, the checkpoint process writes all committed transactions to the database on the disk.
  5. A single transaction can include many data modifications. Each transaction starts with a BEGIN TRANSACTION marker. If the application completes all data modifications successfully, the transaction ends with a COMMIT TRANSACTION marker. Such a transaction is referred to as a committed transaction.

Figure 5.2 How the transaction log works

During normal operation, the checkpoint process routinely checks for committed transactions that have not been written to the data file. The checkpoint process writes the modifications to the data file and checkpoints the transaction to indicate that it has been written to the data file.

If the system fails, the automatic recovery process begins when the SQL Server is restarted. This process uses the transaction log to roll forward (apply the modifications to the data) all committed transactions that have not been checkpointed and roll back (remove) any incomplete transactions.

Transaction logging in SQL Server is not optional. You cannot turn it off, and all normal data modifications must go through the transaction log. For this reason, it is important that the transaction log never become full, as this will prevent data modification in the database. SQL Server does, however, allow two methods of bulk data loading that bypass transaction logging: the bulk copy program (bcp) and the SELECT INTO statement.

CAUTION


Under most circumstances if the hard disk of the computer has a disk-caching controller, you should disable it. Unless a write-caching disk controller is designed specifically for a database, it can seriously harm SQL Server data integrity. Check with your vendor to determine whether the hardware write-caching mechanism of your hard disk is designed for use with a database server.

Lesson Summary

Understanding the structure of a database is crucial to effectively managing resources. The appropriate use of the transaction log can lead to quicker data processing as well as easier data recovery in case of data loss. Understanding how a database uses space allows for better planning and therefore less waste.

Категории