DbMigration: How to use IF EXISTS in SQL()
Please I have a web App with lots of migrations.
I need to drop an index first if it exist before creating it.
In the Dbmigration method. I used
DropIndex("[Log]", "[IX_ContentL]")
But it throws error, the specified index does not exist.
So I tried to first check if the index exist or not using
Sql(" IF EXISTS(SELECT * FROM sys.indexes WHERE name=[IX_ContentL] AND object_Id = [dbo].[Log]) DROP INDEX ([IX_ContentL]);");
But it throws an unable to parse statement error with the following information.
[Token Line 1, Token offset 1, Token error IF]
Please help me, I've been on this 3 days now.
I've tried different combination as suggested on different blogs.
It seems the Sql() function does not recognize the IF EXISTS statement.
Please I need help.
Thanks.


Salman BegRank #284 · 8.8K reputationPosted Mar 11, 2019, 11:51 PM EDT
Amit MohantyRank #112 · 20K reputationPosted Mar 13, 2019, 2:45 AM EDT
Nirav GandhiRank #545 · 4.5K reputationPosted May 23, 2019, 9:14 PM EDT