gpt4 book ai didi

sql-server - 非企业版SQL Server在线索引

转载 作者:行者123 更新时间:2023-12-01 08:09:53 24 4
gpt4 key购买 nike

我正在尝试根据 SQL Server 版本实现逻辑:

IF SERVERPROPERTY('EngineEdition') = 3 /* Enterprise */ OR SERVERPROPERTY('EngineEdition') = 5 /* SQL Azure */
BEGIN
CREATE NONCLUSTERED INDEX IX_MobileDeviceId_with_include ON dbo.FineActivations (MobileDeviceId) INCLUDE (ActivationTime, FineId) WITH (ONLINE = ON);
END

在 SQL Server Express 上,IF 中的条件不满足。但它仍然会产生以下错误:

Online index operations can only be performed in Enterprise edition of SQL Server.

有没有可能克服它?

最佳答案

不可能在 Express 版中引用 Enterprise 功能,它不会在句法上进行验证。您可以使用动态 SQL 解决问题。

DECLARE @sqlcmd nvarchar(4000)
SET @sqlcmd = ' CREATE NONCLUSTERED INDEX IX_MobileDeviceId_with_include ON dbo.FineActivations (MobileDeviceId) INCLUDE (ActivationTime, FineId) '

if SERVERPROPERTY('EngineEdition') = 3 /* Enterprise */ OR SERVERPROPERTY('EngineEdition') = 5 /* SQL Azure */
begin
set @sqlcmd = @sqlcmd +'
with (online = on)'
end
else
begin
set @sqlcmd = @sqlcmd + '
with (fillfactor = 80)'
end

if ((select indexproperty(object_id('FineActivations'),'IX_MobileDeviceId_with_include','IndexID')) is null)
BEGIN
EXEC (@sqlcmd)
END

关于sql-server - 非企业版SQL Server在线索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37458082/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com