Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
CHAPTER 6 CREATING INDEXES AND DATABASE DIAGRAMMING administrators. However, it is useful to know that a tool exists that can aid you in keeping your database tuned well. Getting the indexes right is crucial to your SQL Server database running in an optimal fashion. Spend time thinking about the indexes, try to get them right, and then review them at regular intervals. Review clustering, uniqueness, and especially the columns contained within indexes so that you ensure the data are retrieved as quickly as possible. Finally, also ensure that the order of the columns within the index will reduce the number of reads that SQL Server has to do to find the data. An index where the columns are defined as FirstName, LastName, and Department might be better defined as Department, FirstName, and LastName if the greatest number of queries is based on finding someone within a specific department or listing employees of a department. The difference between these two indexes is that in the first, SQL Server would probably need to perform a table scan to find the relevant records. Compare that with the second example, where SQL Server would search the index until it found the right department, and then just continue to return rows from the index until the department changed. As you can see, the second involves much less work. Creating an Index Now that you know what an index is and you have an understanding of the various types of indexes, let's proceed to create some in SQL Server. There are many different ways to create indexes within SQL Server, as you might expect. Those various methods are the focus of this section of the chapter, starting with how to use the table designer in SQL Server Management Studio. The first index you will place into the database will be on the LastName and the ZipCode fields within the CustomerDetails.Customers table.