"Invalid usage of the option ONLINE in the ALTER TABLE statement" 在 SQL 服务器中添加约束时 ONLINE = ON

"Invalid usage of the option ONLINE in the ALTER TABLE statement" in SQL Server when add constraint with ONLINE = ON

当我尝试在 SQL 服务器中以在线模式(即:WITH (ONLINE = ON))向现有 table 添加检查约束时,出现上述错误。 SQL服务器是否支持在线模式添加校验约束?

ALTER TABLE abc.sample_table
    ADD CONSTRAINT [some_constraint]
        CHECK ([column1] NOT IN (5, 9) OR ([column1] IN (5, 9) AND [column2] != 0))
        WITH (ONLINE = ON)

来自 Microsoft 文档,它是仅用于删除集群约束的选项:

ONLINE = { ON | OFF } <as applies to drop_clustered_constraint_option>

which 指定在索引操作期间是否可以使用底层表和关联索引进行查询和数据修改。默认为关闭。您可以 运行 重建为在线操作。

来源:microsoft Documentations