Skip to content

Instantly share code, notes, and snippets.

@timgabrhel

timgabrhel/indexes.sql Secret

Created Dec 4, 2019
Embed
What would you like to do?
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