Home > Enterprise >  "Invalid usage of the option ONLINE in the ALTER TABLE statement" in SQL Server when add c
"Invalid usage of the option ONLINE in the ALTER TABLE statement" in SQL Server when add c

Time:10-07

When I tried to add a check constraint to an existing table in SQL Server in online mode (i.e.: WITH (ONLINE = ON)) I got the above error. Is it supported to add check constraint in online mode in SQL Server?

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)

CodePudding user response:

from Microsoft documentation , it's an option only for drop clustered constraints :

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

which Specifies whether underlying tables and associated indexes are available for queries and data modification during the index operation. The default is OFF. You can run REBUILD as an ONLINE operation.

source : microsoft Documentations

  • Related