SQL Server:如何编写alter index语句以将列添加到唯一索引? [英] SQL Server: how to write an alter index statement to add a column to the unique index?

查看:185
本文介绍了SQL Server:如何编写alter index语句以将列添加到唯一索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在目前使用4列索引的表上有一个 UNIQUE,NON CLUSTERED 索引。

I have a UNIQUE, NON CLUSTERED index on a table that is currently using 4 columns for the index.

我想创建一个只能在此索引中添加另一列的alter脚本。新列类型为 varchar

I want to create an alter script that can merely add another column to this index. The new column type is varchar.

数据库是SQL Server 2005.

The database is SQL Server 2005.

提前致谢。

推荐答案

你不能改变一个指数 - 所有你能做的就是

You cannot alter an index - all you can do is


  1. 删除旧索引( DROP INDEX(indexname)ON(tablename)

  2. 使用其中的附加列重新创建新索引:

  1. drop the old index (DROP INDEX (indexname) ON (tablename))
  2. re-create the new index with the additional column in it:

  CREATE UNIQUE NONCLUSTERED INDEX (indexname)
  ON dbo.YourTableName(columns to include)


< SQL Server中的code> ALTER INDEX 语句可用于更改现有索引的某些属性(存储属性等),但不允许更改构成索引的列。

The ALTER INDEX statement in SQL Server is available to alter certain properties (storage properties etc.) of an existing index, but it doesn't allow changes to the columns that make up the index.

这篇关于SQL Server:如何编写alter index语句以将列添加到唯一索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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