SQL Server中基于函数的索引 [英] Function-based indexes in SQL Server

查看:797
本文介绍了SQL Server中基于函数的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在PostgreSQL中,我可以创建一个基于函数的索引,而不是在Oracle或PostgreSQL中存在类似于Oracle或PostgreSQL的基于索引的索引使用以下语法使用:

  CREATE INDEX sample ONTestDB((expression1||''||表达式2\" )); 

我发现了一个文章,在SQL Server中我发现了一些名为计算列上的索引的东西。这是一个基于函数的索引,就像在Oracle / PostgreSQL中一样?任何人都可以提供一个示例查询来创建/查看这样的索引?

解决方案

我根据Damien的评论进一步研究了发现一个答案非常接近于匹配Oracle / PostgreSQL基于函数的索引。



我有一个名为 PARCELS 在那里我通过使用以下给出的alter语句创建了一个新列 COMPUTEDPARCELS

  ALTER TABLE [PARCELS] ADD COMPUTEDPARCELS AS CONVERT(CHAR(8),[MAPNO],112); 

然后在计算列上创建一个索引:

  CREATE INDEX function_index ON [PARCELS](COMPUTEDPARCELS); 

当然,这个例子很简单,但行为就像一个基于函数的索引。


I'm trying to understand if function based indexes similar to the one's in Oracle or PostgreSQL exist in SQL Server

In PostgreSQL, I can create a function based index using by using the following syntax:

CREATE INDEX sample ON "TestDB" (("expression1" || ' ' || "expression2"));

I found a article where I found something called "index on computed columns" in SQL Server. Is this a function based index just like in Oracle/PostgreSQL? Can anybody provide me a sample query to create/view such an index?

解决方案

I researched a bit further based on Damien's comment and found an answer that comes very close to matching Oracle's/PostgreSQL's function based indexes.

I have a table named PARCELS where I created a new column COMPUTEDPARCELS by using the alter statement as given below:

ALTER TABLE [PARCELS] ADD COMPUTEDPARCELS AS CONVERT(CHAR(8), [MAPNO], 112);

And then create an index on the computed column:

CREATE INDEX function_index ON [PARCELS](COMPUTEDPARCELS);

Of course the example is pretty simple but behaves just like a function based index.

这篇关于SQL Server中基于函数的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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