在部分 CHAR 列上创建索引 [英] Create Index on partial CHAR Column

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

问题描述

我有一个 CHAR(250) 列用作 varchar(24) 列的外键.

I have a CHAR(250) column being used as a foreign key to a varchar(24) column.

在 MySQL 中,我记得我可以创建一个指定 column(24) 的索引,以便在最左边的 24 个字符上创建一个索引.这在 MS SQL Server 上似乎是不可能的.

In MySQL I recall that I could create an index specifying column(24) in order to create an index on the leftmost 24 characters. This doesn't appear to be possible on MS SQL Server.

我的问题是:

是否可以在 SQL Server 2008 上使用索引视图来索引该列的子字符串,如果可以,是否会对表的性能产生任何副作用?

Is it possible to use an indexed view on SQL Server 2008 to index a substring of that column, and if so, would it have any side-effects on the table's performance?

推荐答案

你可以创建一个持久化的计算列,然后索引它,参见 在计算列上创建索引

You can create a persisted computed column, then index it, see Creating Indexes on Computed Columns

alter table add newcolumn as cast(oldcolumn as varchar(24)) persisted;
create index table_newcolumn on table (newcolumn);

这篇关于在部分 CHAR 列上创建索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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