SQL Server 添加索引而不删除表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39710431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Server add index without dropping table
提问by Roger Dodger
I need to add an index to a table that already has the primary key indexed. The new index will be on another column.
我需要向已经有主键索引的表添加索引。新索引将在另一列上。
I don't have enough permissions on this table to select 'Alter' by right clicking and selecting 'Script table as'.
我对此表没有足够的权限,无法通过右键单击并选择'Script table as'来选择 'Alter '。
Is there any way to add an index to a column without effecting any of the existing data?
有没有办法在不影响任何现有数据的情况下向列添加索引?
myTable:
- id -- int -----> this is an identity column, set as PK and indexable
- bookid ---> varchar(20) ----> this is the column that needs index created
我的表:
- id -- int -----> 这是一个标识列,设置为 PK 和可索引
- bookid ---> varchar(20) ----> 这是需要创建索引的列
回答by Kannan Kandasamy
You can execute create index script as below, which is similar to what Igor mentioned
您可以执行如下创建索引脚本,这类似于 Igor 提到的
CREATE NONCLUSTERED INDEX IX_YourTable ON dbo.YourTable (bookid)