Click here to Skip to main content
14,644,614 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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)
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100