Skip to content

Instantly share code, notes, and snippets.

@timgabrhel
Created December 4, 2019 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timgabrhel/d649074cbe82016e8a90f918c58c4764 to your computer and use it in GitHub Desktop.
Save timgabrhel/d649074cbe82016e8a90f918c58c4764 to your computer and use it in GitHub Desktop.
messages indexes
CREATE NONCLUSTERED INDEX [ix_Messages_MessageThreadId] ON [dbo].[Messages]
(
[MessageThreadId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [ix_Messages_ToUserId_ReadDate_Deleted] ON [dbo].[Messages]
(
[ToUserId] ASC,
[ReadDate] ASC,
[Deleted] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ToUserId_Deleted_Includes] ON [dbo].[Messages]
(
[ToUserId] ASC,
[Deleted] ASC
)
INCLUDE ( [MessageThreadId],
[FromUserId],
[Message],
[SendDate],
[ReadDate]) WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [nci_wi_Messages_9AB8B9D5FFD025E77AAB65C886618783] ON [dbo].[Messages]
(
[FromUserId] ASC,
[Deleted] ASC
)
INCLUDE ( [Message],
[MessageThreadId],
[ReadDate],
[SendDate],
[ToUserId]) WITH (STATISTICS_NORECOMPUTE = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Messages] ADD CONSTRAINT [PK_Messages] PRIMARY KEY CLUSTERED
(
[MessageId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment