-- Index creation example with re-runnable script
-- For some prefixing indexes with IDX_ seems good
IF NOT EXISTS(SELECT 1 FROM [sys].[indexes] WHERE [name] = 'IX_TableName_IncludedColumn1_IncludedColumn2')
BEGIN
CREATE INDEX [IDX_TableName_IncludedColumn1_IncludedColumn2] ON [TableName] ([IncludedColumn1], [IncludedColumn2]);
END
-- Others prefix indexes with IX_
IF NOT EXISTS(SELECT 1 FROM [sys].[indexes] WHERE [name] = 'IX_TableName_IncludedColumn1_IncludedColumn2')
BEGIN
CREATE INDEX [IX_TableName_IncludedColumn1_IncludedColumn2] ON [TableName] ([IncludedColumn1], [IncludedColumn2]);
END
-- Example table creation re-runnable
IF OBJECT_ID('TableName', 'U') IS NULL
BEGIN
CREATE TABLE [TableName] (
[TableNameId] INT PRIMARY KEY,
[IncludedColumn1] VARCHAR(20) NOT NULL,
[IncludedColumn2] VARCHAR(50) NOT NULL
);
END