TAILIEUCHUNG - Beginning SQL Server 2008 for Developers From Novice to Professional phần 5

Một điều quan trọng sử dụng các chỉ số trên ràng buộc tham chiếu trong một bảng. Nếu bạn nhớ lại từ chương 3, một hạn chế tham chiếu là nơi bạn đã chỉ ra rằng thông qua việc sử dụng của một hành động chính, một số hạn chế tùy thuộc vào những dữ liệu có. Để cung cấp cho một ví dụ nhanh chóng của một ràng buộc tham chiếu, | CHAPTER 6 CREATING INDEXES AND DATABASE DIAGRAMMING 155 Primary and Foreign Keys One important use of indexes is on referential constraints within a table. If you recall from Chapter 3 a referential constraint is where you ve indicated that through the use of a key certain actions are constrained depending on what data exists. To give a quick example of a referential constraint say you have a customer who owns banking products. A referential constraint would prevent the customer s record from being deleted while those products existed. SQL Server does not automatically create indexes on your foreign keys. However as the foreign key column values need to be identified by SQL Server when joining to the parent table it is almost always recommended that an index be created on the columns of the foreign key. Finding Specific Records Ideal candidates for indexes are columns that allow SQL Server to quickly identify the appropriate rows. In Chapter 8 we ll meet the WHERE clause of a query. This clause lists certain columns in your table and is used to limit the number of rows returned from a query. The columns used in the WHERE clause of your most common queries make excellent choices for an index. So for example if you wanted to find a customer s order for a specific order number an index based on customer_id and order_number would be perfect as all the information needed to locate a requested row in the table would be contained in the index. If finding specific records is going to make up part of the way the application works then do look at this scenario as an area for an index to be created. Using Covering Indexes As mentioned earlier when you insert or update a record any data in a column that is included in an index is stored not only in the table but also in the indexes for nonclustered indexes. From finding an entry in an index SQL Server then moves to the table to locate and retrieve the record. However if the necessary information is held within the index then .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.