Search code examples
sqlsql-server-2008indexingindices

MS SQL: Do you only index tables with many columns?


I have local temp tables and they generally have only two to three columns, can these be indexed?


Solution

  • Yes, for instance with this:

    CREATE TABLE #Users
    (
        ID          INT IDENTITY(1,1),
        UserID      INT,
        UserName    VARCHAR(50)
    )
    CREATE CLUSTERED INDEX IDX_C_Users_UserID ON #Users(UserID)
    
    CREATE INDEX IDX_Users_UserName ON #Users(UserName)
    

    ref: http://sqlserverplanet.com/tsql/create-index-on-temp-table