CREATE TABLE MySpatialTable(id int primary key, geometry_col
geometry);
CREATE SPATIAL INDEX SIndx_MySpatialTable_geometry_col1
ON MySpatialTable(geometry_col)
WITH ( BOUNDING_BOX = ( 0, 0, 500, 200 ) );
Query Index có liên quan đ n d li u metadata:ế ữ ệ
5. Tìm ki m t t c index:ế ấ ả
Tr c tiên, n u mu n tìm ki m t t c index thì hãy s d ng câu l nh truy ướ ế ố ế ấ ả ử ụ ệ
v n – query theo b ng, c t và khóa index c a c s d li u s n có.ấ ả ộ ủ ơ ở ữ ệ ẵ
SELECT OBJECT_SCHEMA_NAME(BaseT.[object_id],DB_ID()) AS
[Schema],
BaseT.[name] AS [table_name], I.[name] AS [index_name], AC.[name] AS
[column_name],
I.[type_desc]
FROM sys.[tables] AS BaseT
INNER JOIN sys.[indexes] I ON BaseT.[object_id] = I.[object_id]
INNER JOIN sys.[index_columns] IC ON I.[object_id] = IC.[object_id]
INNER JOIN sys.[all_columns] AC ON BaseT.[object_id] = AC.[object_id]
AND IC.[column_id] = AC.[column_id]
WHERE BaseT.[is_ms_shipped] = 0 AND I.[type_desc] <> 'HEAP'
ORDER BY BaseT.[name], I.[index_id], IC.[key_ordinal]
6. Fragmentation:
Còn v i quá trình Fragmentation – tìm ki m nh ng thành ph n index trong ớ ế ữ ầ
tình tr ng “Fragmentation” c a t t c các b ng d li u trong database hi n ạ ủ ấ ả ả ữ ệ ệ
t i. Ví d nh sau:ạ ụ ư
SELECT object_name(IPS.object_id) AS [TableName],
SI.name AS [IndexName],
IPS.Index_type_desc,
IPS.avg_fragmentation_in_percent,