Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 36 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
36
Dung lượng
346 KB
Nội dung
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes Indexes / Session 2/ 2 of 36 Module 1 - Review Data Integrity Data Integrity ensures accurate and up-to-date information at any point in time. In SQL Server 2005, data integrity is enforced using Constraints, Default Values, Rules and Triggers. Types of Data Integrity To maintain accuracy and consistency of data in a relational database. Four types of integrity checks: Entity Integrity, Domain Integrity, Referential Integrity, User-defined Integrity. Integrity Constraints To ensure validity and consistency of data in a database. SQL Server 2005 supports UNIQUE, CHECK, PRIMARY and FOREIGN KEY constraints on columns in a table. Indexes / Session 2/ 3 of 36 Module 2 - Review Index is used for faster retrieval of data. When an index is created on a table, the index creates an order for the data rows or records in the table. All indexes are structured in the form of B-Trees. Indexes types Clustered indexes Non-clustered indexes XML indexes Indexes / Session 2/ 4 of 36 Types of Indexes Objectives Indexes / Session 2/ 5 of 36 Types of Indexes Clustered index stores data in a sorted manner. A table can have only one clustered index because the clustered index defines the order of the physical storage of data. Nonclustered index does not physically rearrange the data in the database. They just create pointers pointing to physical data rows. SQL Server 2005 supports up to 249 nonclustered indexes on a table. Indexes / Session 2/ 6 of 36 Characteristics of Indexes The characteristics of an index are based on the type and number of fields included in the index as well as the index options specified when creating the index. Indexes can be classified as: Unique Index Composite Index Full-Text Index XML Index Indexes / Session 2/ 7 of 36 Description Types of Indexes Unique Index: can be defined on a column with no duplicate values. If a table has a column with a PRIMARY KEY, a unique clustered index is automatically defined on that column. If a table has a column with a UNIQUE constraint, then a unique nonclustered index is automatically created on that column. Composite Index: created on two or more columns. Both clustered and nonclustered indexes can be composite indexes. Full-Text Index: allows complex queries to be performed on character data. Using the Full-Text indexing feature, searches can be performed on individual words, two or more adjacent words, phrases, parts of words or inflectional words (such as drunk for drink). XML Index: clustered and nonclustered XML index can be created on a column with XML data. Indexes / Session 2/ 8 of 36 Index Design Guidelines Indexes should be created based on the type of data, the amount of data present, the frequency of updates and the frequency of queries made on the table. List of rules and guidelines: An index can have a maximum of 16 columns. Too many indexes decrease the performance of INSERT, UPDATE and DELETE statements. Indexes should be used to improve query performance on tables with low update requirements but large volumes of data. Maintain indexes even on small tables if data may later be added into the table. Indexes / Session 2/ 9 of 36 There are two methods by which you can create an index: Using the CREATE INDEX command of Transact-SQL. Using the SQL Server Management Studio. Creating Indexes Indexes / Session 2/ 10 of 36 Syntax: CREATE INDEX <index_name> ON <table_name> (<column_name>) where index_name: specifies the name of the index. table_name: specifies the name of the table. column_name: specifies the name of the column. Example: CREATE INDEX IX_Country ON Customer_Details(Country) Using “CREATE INDEX” . table. All indexes are structured in the form of B-Trees. Indexes types Clustered indexes Non-clustered indexes XML indexes Indexes / Session 2/ 4 of 36 Types of Indexes Objectives Indexes. Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes Indexes / Session 2/ 2 of 36 Module 1 - Review Data. data rows. SQL Server 2005 supports up to 249 nonclustered indexes on a table. Indexes / Session 2/ 6 of 36 Characteristics of Indexes The characteristics of an index are based on the type