Function-based indexes in SQL Server(SQL Server 中基于函数的索引)
问题描述
我试图了解 SQL Server 中是否存在类似于 Oracle 或 PostgreSQL 中的基于函数的索引
I'm trying to understand if function based indexes similar to the one's in Oracle or PostgreSQL exist in SQL Server
在 PostgreSQL 中,我可以使用以下语法创建基于函数的索引:
In PostgreSQL, I can create a function based index using by using the following syntax:
CREATE INDEX sample ON "TestDB" (("expression1" || ' ' || "expression2"));
我发现了一篇文章,其中我发现了一个名为index onSQL Server 中的计算列.这是一个基于函数的索引,就像在 Oracle/PostgreSQL 中一样吗?谁能给我提供一个示例查询来创建/查看这样的索引?
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?
推荐答案
我根据 Damien 的评论进行了进一步研究,并找到了一个非常接近匹配 Oracle/PostgreSQL 基于函数的索引的答案.
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.
我有一个名为 PARCELS
的表,我在其中使用如下所示的更改语句创建了一个新列 COMPUTEDPARCELS
:
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 中基于函数的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL Server 中基于函数的索引


基础教程推荐
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01