Tutorial by Examples

With a clustered index the leaf pages contain the actual table rows. Therefore, there can be only one clustered index. CREATE TABLE Employees ( ID CHAR(900), FirstName NVARCHAR(3000), LastName NVARCHAR(3000), StartYear CHAR(900) ) GO CREATE CLUSTERED INDEX IX_Clustered O...
Non-clustered indexes have a structure separate from the data rows. A non-clustered index contains the non-clustered index key values and each key value entry has a pointer to the data row that contains the key value. There can be maximum 999 non-clustered index on SQL Server 2008/ 2012. Link for r...
SP_HELPINDEX tableName
CREATE VIEW View_Index02 WITH SCHEMABINDING AS SELECT c.CompanyName, o.OrderDate, o.OrderID, od.ProductID FROM dbo.Customers C INNER JOIN dbo.orders O ON c.CustomerID=o.CustomerID INNER JOIN dbo.[Order Details] od ON o.OrderID=od.OrderID GO CREATE UNIQUE C...
DROP INDEX IX_NonClustered ON Employees
sys.dm_db_index_physical_stats ( { database_id | NULL | 0 | DEFAULT } , { object_id | NULL | 0 | DEFAULT } , { index_id | NULL | 0 | -1 | DEFAULT } , { partition_number | NULL | 0 | DEFAULT } , { mode | NULL | DEFAULT } ) Sample : SELECT * FROM sys.dm_db_inde...
avg_fragmentation_in_percent valueCorrective statement>5% and < = 30%REORGANIZE>30%REBUILD ALTER INDEX IX_NonClustered ON tableName REORGANIZE; ALTER INDEX ALL ON Production.Product REBUILD WITH (FILLFACTOR = 80, SORT_IN_TEMPDB = ON, STATISTICS_NORECOMPUTE = ON);
Rebuilding indexes is done using the following statement ALTER INDEX All ON tableName REBUILD; This drops the index and recreates it, removing fragementation, reclaims disk space and reorders index pages. One can also reorganize an index using ALTER INDEX All ON tableName REORGANIZE; which ...
EXEC sp_MSForEachTable 'ALTER INDEX ALL ON ? REBUILD'
You could use "SP_HELPINDEX Table_Name", but Kimberly Tripp has a stored procedure (that can be found here), which is better example, as it shows more about the indexes, including columns and filter definition, for example: Usage: USE Adventureworks EXEC sp_SQLskills_SQL2012_helpindex ...

Page 1 of 1