0

I have a recommendation from Azure to create the following index:

CREATE NONCLUSTERED INDEX [nci_wi_Transactions_71EA7D20388C3F47A9B9EBF2A1C7BA0C] ON [dbo].[Transactions] ([Client_Id]) INCLUDE ([Date], [Description], [Size], [Type]) WITH (ONLINE = ON)

Is it possible to execute this SQL directly from MSSQL without affecting my applications work? Or do I need to apply some migrations from code-first to keep database context with the correct state anyway?

arteny
  • 339
  • 1
  • 4
  • 14
  • Wouldn't matter unless you create the database from scratch via migrations. Otherwise, add it in: https://stackoverflow.com/questions/21192603/creating-indexes-with-entity-framework-6-migrations – Steve Greene Jan 31 '22 at 15:27
  • @SteveGreene, all database objects are created from code-first (using update-database). Your link explains how to create an index from code-first code, when my question is: is it possible to avoid this and create directly from MSSQL? – arteny Feb 02 '22 at 09:05
  • 1
    No, you don't need it in EF for the app to keep working or to realize the performance gain - although WHERE clause would be key for index use. Indices are behind the scenes at the SQL level. If you recreate the database from scratch, those objects won't be there unless you maintain a post creation script of some kind or do a schema compare. – Steve Greene Feb 02 '22 at 15:36

1 Answers1

0

Actually, @Steve in comment answered and I checked in runtime and Yes, it is safe to create an index directly from a database, which will not affect applications, used not changed DbContext.

arteny
  • 339
  • 1
  • 4
  • 14