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 中基于函数的索引
基础教程推荐
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
