0

In SQL Server, I can create a non clustered index like this:

CREATE NONCLUSTERED INDEX idx_My_Table
ON [dbo].[MyTable] ([my_field_1])
INCLUDE ([my_field_2],[my_field_3],[my_field_4])

In MySQL, I create the index as

ALTER TABLE `MyTable` 
  ADD INDEX `idx_My_Table` (`my_field_1`, `my_field_2`, `my_field_3`, `my_field_4`);

Is there an exact equivalent of the SQL Server construct in MySQL or the closest that can be changed to achieve it?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Bhans345
  • 39
  • 1
  • 3
  • 2
    Any index other than the primary key index is a non clustered index. Your `ALTER` statement is creating a non clustered index. – Tim Biegeleisen Mar 18 '22 at 10:39
  • 1
    ... if the table does not contain primary key then first unique index without nullable columns is clustered. If no such index then the index by autogenerated inner row number (not accessible) will be clustered. All another indices are not clustered ones. This everything deals about InnoDB tables. The tables which uses another engines have their own rules. – Akina Mar 18 '22 at 10:43

0 Answers0