如何在现有临时表上创建索引。 [英] How to create index on existing temp table.

查看:432
本文介绍了如何在现有临时表上创建索引。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的数据库中有一个临时表。

在我的项目中,我想根据一个特定的列显示临时表记录(假设为SRNO)。

我的查询是我想让我的选择查询优化为此目的我想在特定列ieSRNO上创建一个索引。

请让我知道如何在已存在的临时表上创建索引column。

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.

推荐答案

查找下面的示例



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)


这篇关于如何在现有临时表上创建索引。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆