I am using Microsoft SQL Server 2017. I have table called ProductMapping. Below is the table structure:
CREATE TABLE [dbo].[Accommodation_ProductMapping](
[ProductMappingId] [uniqueidentifier] NOT NULL,
[AccommodationId] [uniqueidentifier] NULL,
[SupplierId] [uniqueidentifier] NULL,
[SupplierId] [varchar](50) NULL,
[SupplierName] [varchar](50) NULL,
[SupplierProductReference] [nvarchar](255) NULL,
[ProductName] [nvarchar](500) NULL,
[CountryName] [nvarchar](255) NULL,
[CountryCode] [nvarchar](50) NULL,
[CityName] [nvarchar](255) NULL,
[CityCode] [nvarchar](100) NULL
)
This table has 15 billion data. I have created the non cluster & composite indexes on this table. Below are the details:-
CREATE NONCLUSTERED INDEX [IDX_CityCode] ON [dbo].[ProductMapping]
(
[CityCode] ASC
)
CREATE NONCLUSTERED INDEX [IDX_CountryCode] ON [dbo].[ProductMapping]
(
[CountryCode] ASC,
)
CREATE NONCLUSTERED INDEX [IDX_CountryCityCode] ON [dbo].[ProductMapping]
(
[CountryCode] ASC,
[CityCode] ASC
)
CREATE NONCLUSTERED INDEX [IDX_ProductCountryCityCode] ON [dbo].[ProductMapping]
(
[ProductName] ASC,
[CountryCode] ASC,
[CityCode] ASC
)
CREATE NONCLUSTERED INDEX [IDX_AccommodationCountryCityCode] ON [dbo].[ProductMapping]
(
[AccommodationId] ASC,
[CountryCode] ASC,
[CityCode] ASC
)
I am able to get the data without any issue.
I just want to know is there any unused or redundant Indexes which I created above?
Also, I have created a composite index "IDX_CountryCityCode" on country and city code, so do I need an individual non-cluster index for "CityCode" and "CountryCode" (e.g. IDX_CityCode and IDX_CountryCode).
Thank you in advance.
EDITED
I just want to know if I remove all the above indexes (i.e. [IDX_CityCode], [IDX_CountryCode], [IDX_CountryCityCode], [IDX_ProductCountryCityCode] & [IDX_AccommodationCountryCityCode]
) and put them all in one composite index as below. Is this going to work or is it best approach?
CREATE NONCLUSTERED INDEX [IDX_CityCountryAccommodationProduct] ON [dbo].[ProductMapping]
(
[CityCode] ASC,
[CountryCode] ASC,
[AccommodationId] ASC,
[ProductName] ASC
)