-- Run with QUOTED_IDENTIFIER ON. SiteCalls / Notifications / AuditLog all carry -- filtered indexes (and AuditLog persisted computed columns), and SQL Server -- refuses BOTH the filtered-index DDL below and any later DML on those tables -- with error 1934 when the session has QUOTED_IDENTIFIER OFF -- which is exactly -- what `sqlcmd` gives you by default (pass -I, or keep this header). The SETs sit -- in their own batch so they are in force when the statements after the GO parse. SET QUOTED_IDENTIFIER ON; SET ANSI_NULLS ON; GO BEGIN TRANSACTION; IF NOT EXISTS ( SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20260814235335_AddAuditLogAndNotificationCoveringIndexes' ) BEGIN EXEC(N'CREATE INDEX [IX_Notifications_Delivered] ON [Notifications] ([DeliveredAt]) WHERE [Status] = ''Delivered'''); END; IF NOT EXISTS ( SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20260814235335_AddAuditLogAndNotificationCoveringIndexes' ) BEGIN DROP INDEX IX_AuditLog_OccurredAtUtc ON dbo.AuditLog; CREATE NONCLUSTERED INDEX IX_AuditLog_OccurredAtUtc ON dbo.AuditLog (OccurredAtUtc DESC) INCLUDE (Status) ON ps_AuditLog_Month(OccurredAtUtc); END; IF NOT EXISTS ( SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20260814235335_AddAuditLogAndNotificationCoveringIndexes' ) BEGIN INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion]) VALUES (N'20260814235335_AddAuditLogAndNotificationCoveringIndexes', N'10.0.7'); END; COMMIT; GO