Skip to content
Advertisement

Check duplicate indexes that is combination of multiple columns

I’ve a unique index (UQ_index1) created using

CREATE UNIQUE INDEX UQ_index1 on product_table
(
  column1,
  column2
)
INCLUDE
(
  column3
)
WITH (DATA_COMPRESSION=PAGE)
ON scheme_Product(column1)
  1. Somehow my table is messed and I’ve few duplicate rows in table. How can I create a query that will help me get the duplicate items with combination of three columns (column1, column2, column3) in the product_table
  2. What is the suggested ways to get ride of duplicate key situation?

Advertisement

Answer

I think a simple group by query should be sufficient to return the duplicates

SELECT column1, column2, column3
FROM product_table
GROUP BY column1, column2, column3
HAVING COUNT(*) > 1

But I am not sure what you mean by duplicates, as your unique index does not allow duplicates.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement