Click here to Skip to main content
15,917,174 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having one temporary table in my database.
In my project i wants to display the temporary table records based on one particular column (assume "SRNO").
My query is i wants to make my select query optimize for that purpose i wants to create one index on the particular column i.e.SRNO.
Please let me know how to create index on already existed temporary table column.
Posted
Updated 21-May-14 1:39am
v2

1 solution

find the example below

CREATE TABLE #Users
    (
        ID          INT IDENTITY(1,1),
        UserID      INT,
        UserName    VARCHAR(50)
    )
    
    INSERT INTO #Users
    (
        UserID,
        UserName
    )   
    SELECT 
         UserID     = u.UserID
        ,UserName   = u.UserName
    FROM dbo.Users u
    
    CREATE CLUSTERED INDEX IDX_C_Users_UserID ON #Users(UserID)
    
    CREATE INDEX IDX_Users_UserName ON #Users(UserName)
 
Share this answer
 
Comments
sarath Nath 21-May-14 7:56am    
I have tried this it showing error like "#tempsample does not exist"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900