I have this table:
CREATE TABLE [dbo].[relatea] (
[mid] [varchar](16) NOT NULL,
[sid] [varchar](16) NOT NULL
)
It stores hash matches. Is there any benefit to having this as a heap? It has around 7 million rows, and the values are not unique in either column. I know heaps are generally never good for any large tables. This table currently has no indexes.
I was thinking of altering the table to:
CREATE TABLE [dbo].[relatea] (
[mid] [varchar](16) NOT NULL,
[sid] [varchar](16) NOT NULL,
CONSTRAINT [pk_relatea] PRIMARY KEY CLUSTERED (
[mid] ASC,
[sid] ASC
)
)
Table queries are generally but not always on sid
, and the combination of mid
and sid
should always be unique.
Is it better to create a clustered index like this, as opposed to leaving the table as a heap?
sid
should be the first option to index.