I'm trying to understand if function based indexes similar to the one's in Oracle or PostgreSQL exist in SQL Server
我想知道在SQL Server中是否存在与Oracle或PostgreSQL中类似的基于函数的索引
In PostgreSQL, I can create a function based index using by using the following syntax:
在PostgreSQL中,我可以使用以下语法创建一个基于函数的索引:
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?
我在SQL Server中找到了一篇文章,在文中我找到了“计算列上的索引”。这是一个基于函数的索引,就像Oracle/PostgreSQL一样吗?谁能提供一个示例查询来创建/查看这样的索引吗?
1 个解决方案
#1
16
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.
我根据Damien的评论做了进一步的研究,找到了一个非常接近于匹配Oracle /PostgreSQL基于函数的索引的答案。
I have a table named PARCELS
where I created a new column COMPUTEDPARCELS
by using the alter statement as given below:
我有一个名为“包裹”的表格,在该表中,我使用下面给出的alter语句创建了一个新的计算包裹栏:
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.
当然,这个例子非常简单,但是行为就像一个基于函数的索引。
#1
16
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.
我根据Damien的评论做了进一步的研究,找到了一个非常接近于匹配Oracle /PostgreSQL基于函数的索引的答案。
I have a table named PARCELS
where I created a new column COMPUTEDPARCELS
by using the alter statement as given below:
我有一个名为“包裹”的表格,在该表中,我使用下面给出的alter语句创建了一个新的计算包裹栏:
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.
当然,这个例子非常简单,但是行为就像一个基于函数的索引。