dbms ไทย บทที่ 13 รู้จักกับอินเด็กซ์ (indexes)
DESCRIPTION
DBMS ไทย บทที่ 13 รู้จักกับอินเด็กซ์ (Indexes)TRANSCRIPT
13
13 (Indexes)
SQL Server SQL Server Constraints Primary Key Constraints Unique Constraints UPDATE, INSERT DELETE SQL Server SQL Server SQL Server Clustered Index ProductName Clustered Index NonClusteered Index Clustered Index Unique Index Clustered Index NonClustered Index Clustered Index NonClustered Index Clustered Index
B-Tree (Leaf) Cluster Index CustomerName TblCustomers CustomerName
Clustered Index SQL Server B-Tree Clustered Index
Clustered Index - Non-leaf Levels Root Page- Non-leaf Levels Intermediate Levels - Non-leaf Levels CustomerName B-Tree 141 Anny Key 101 110 SQL Server intermediate Levels - Leaf Levels
Management Studio - SQL Server Unique Index Primary key UNIQUE constraint
- CREATE INDEX - SQL Server sysindexes - - 1 2 - CustomerID CustomerName Clustered Index Management Studio 1. Indexes New Index 2. New Index
3.
Clustered Index Transact-SQL Clustered Index Management Studio CREATE INDEX
Clusrtered Index CLUSTERED CREATE INDEX
Clustered Index Clustered Index IX_CustomerName CustomerName TbCustomers
DROP_EXISTING
Clustered indexes
SQL Server SELECT
SQL Server
1. SQL Server CustomerName CustomerName Pinny
2. (Root Page) : 140 Pinny Merin Merin 145
3. Non-leaf Level 145 Pinny Merin Smith Merin 130
4. Leaf Level 130 Pinny Clustered Index
Clustered Index BETWEEN, >, >=, Microsoft SQL Server 2005>Performance Tools>Database Engine Tuning Advisor Connect to Server
2. Database Engine Tuning Advisor Session name
- Workload ....... SQL Server Profiler trace files (*.trc) Workload SQL Server Profiler Database for workload analysis Workload
- Select database and tables to tune Orders
3. Tuning Options Limit tuning time Physical Design Structures Clustered Index NonClustered Index
4. Progress Recommendations
5. Action>Apply Recommendations Apply Recommendations Apply now Schedule for later
6. Action>Save Recommendations Transact-SQL
SQL Server Profiler
SQL Server Profiler Workload
Workload
1. SQL Server Profiler Start>All Programs>Microsoft SQL Server 2005>Performance tools>SQL Server Profiler SQL Server Profiler (New Trace) Connect to Server
2. Trace Trace Properties Trace name Save to file (Workload) *.trc
Workload workload master Workload ( Workload Database Engine Tuning Advisor General Workload Table )
Trace Enable trace stop time SQL Server Profiler Workload
RUN Workload
3. ( Management Studio ) SQL Server Profiler Workload
,
Management Studio
Transact-SQL
Management Studio sp_rename
IX_TblProducts IX_ProductName
Clustered Index NonClustered Index Clustered Index Clustered Index Clustered index Clustered Index Clustered Index DROP_EXISTING CREATE INDEX Clustered Index Management Studio
Delete
Tranact-SQL
IX_ProductName TblProducts
Primary Key Constraints Unique Constraints Management Studio
Properties
Transact-SQL
sp_helpindex
3.3.3. Note
SQL Server ( internal identifier) Clustered Index Clustered Index NonClustered Index Clustered Index NonClustered Index
Add
Remove
Move Up
Move Down
OK
CREATE [ UNOQUE ] [ CLUSTERED| NONCLISTERED ] INDEX index_name
ON{ table | view} (column [ASC | DESC] [,n])
[WITH< index_option >[,n]]
[ON filegroup]
::={PAD_INDEX | FILLFACTOR=fillfactor |IGNORE_DUP_KEY|
DROP_EXISTING | STATISTICS_NORECOMPUTE |
SORT_IN_TEMPDB}
SELECT CustomerName FROM tblCustomer Where CustomerName= Pinny
SELECT* FROM TblCustomers WHERE CustomerName >= AAND CustomerName[,n]]
[ON filegroup]
< index_option > ::={PAD_INDEX | FILLFACTOR= | IGNORE_DUP_KEY | DROP_EXISTING | STATISTICS_NORECOMPUTER | SORT_IN_TEMPDB }
CREATE INDEX CustomerNamelnd ON TblCustomers (CustomerName) WITH FILLFACTOR = 50
Note
Fill Factor Fill Factor 2
Note
Primary Key Constraints Unique Constraints Unique Index
CREATE UNIQUE INDEX IX_ProductID ON TblProducts (ProductID)
CREATE UNIQUE INDEX IX_ProductID ON TblProducts (ProductID) WITH IGNORE_DUP_KEY
Note
Unique Index NULL Unique Index NULL 1 Unique Index
Note
Workload Workload SQL Server Profiler
Connect
> Start Analysis
Connect
Note
SQL Server Profiler Run (Font) Tools>Options Font name UPC
Note
Primary Key Constraints Unique Constraints Primary Key Constraints Unique Constraints
sp_rename [@objname = ] object_name , [@newname = ] new_name [,[@objtype = ] object_type]
EXEC sp_name TblProducts.IX_ProductID,IX_ProductName,INDEX
Note
DROP INDEX table.index / view.index[,n]
DROP INDEX TblProducts.IX_ProductName