Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 27 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
27
Dung lượng
409 KB
Nội dung
Session 2Introduction to Indexes
ReviewIn session 1 we learnt about:Data IntegrityDefine and describe data integrityList the rules for data integrityTypes of Data IntegrityIntegrity ConstraintVarious Types of Indexes
Session ObjectivesIntroduction to IndexesIndex ArchitectureRetrieving Stored DataFinding RowsVarious Types of IndexesWorking with IndexesViewing Index Information
Overview of Data StorageA book contains pages, which contain paragraphs made up of sentences.SQL Server 2005 stores data in storage units known as data pages. These pages contain data in the form of rowsA page type begins with a 94 byte header, which stores system information about the page
Database FilesIn SQL Server 2005, every database is mapped over a set of operating-system files. Databases have their individual files.The data and log information are maintained in separate files.The three types of database files in SQL Server are:Primary data filesSecondary data filesLog filesThe primary data file is the starting point of the database and points to the other files in the database. The suggested filename extension for primarydata files is .mdf mdfSecondary data files consist of all of the data files, excluding the primary data file. The recommended filename extension for secondary data files is .ndf ndf.ldfLog files contain all the log information used to recover the database. Theremust be at least one log file for each database. The recommended filenameextension for log files is .ldf.
IndexesIn a table, records are stored in the order in which they are entered. Their storage in the database is unsorted. -> when data is to be retrieved from such tables, the entire table needs to be scanned. This slows down the query retrieval process.->When an index is created on a table, the index creates an order for the data rows or records in the table.Emp_NoEmp_NameEmp_DOBEmp_DOJ345 James 24-Sep-196830-May-1990873 Pamela 27-Jul-197019-Nov-1993693 Allan 10-Sep-197001-Jul-1992305 Geoff 12-Feb-197329-Oct-1996Emp_No305345693873
Guidelines about indexesIndexes increase the speed of queries that join tables or perform sorting operationsIndexes implement the uniqueness of rows if defined when you create an index.Indexes are created and maintained in ascending or descending orderIndexes should not be created if they are not used frequently since, maintaining them requires time and resourcesIndexes should not be created on columns having duplicate data
Overview of index architectureB-treeRoot NoteIntermediateNodeLeaf Note
Overview of index architectureIndex B-tree StructureIndex pageIndex pageIndex/Data PageIndex/Data PageIndex pageIndex/Data PageIndex/Data PageRoot NoteIntermediateNoteLeaf Note
Overview of index architectureClustered Indexes causes records to be physically stored in a sorted of sequential order, determines the actual order in which data is stored in the databaseNonclustered Indexes is defined on a table that has data either in a clustered structure or a heap. Each index row in the nonclustered index contains a nonclustered key value and a row locatorIndexClustered Index Nonclustered Index
123doc.vn