
/* drop existing PK constraint, indexes */

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[DT412]') AND name = N'PID412DT412')
ALTER TABLE [dbo].[DT412] DROP CONSTRAINT [PID412DT412]

GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[DT412]') AND name = N'SID407DT412')
DROP INDEX [SID407DT412] ON [dbo].[DT412] WITH ( ONLINE = OFF )

GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[DT412]') AND name = N'SID415DT412')
DROP INDEX [SID415DT412] ON [dbo].[DT412] WITH ( ONLINE = OFF )

GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[DT412]') AND name = N'SID445DT412')
DROP INDEX [SID445DT412] ON [dbo].[DT412] WITH ( ONLINE = OFF )

GO

/* create clustered index first, PK constraint second, non-clustered indexes last */

CREATE UNIQUE CLUSTERED INDEX [DT+DBPOS+DI] ON [dbo].[DT412] 
(
	[DI000239] ASC,
	[DI000241] ASC,
	[DI000238] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

GO

ALTER TABLE [dbo].[DT412] ADD  CONSTRAINT [PK_DT412_DI] PRIMARY KEY NONCLUSTERED 
(
	[DI000238] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

GO

CREATE UNIQUE NONCLUSTERED INDEX [PK_covering_query] ON [dbo].[DT412] 
(
	[DI000238] ASC
)
INCLUDE ( [DI000239],
[DI000252],
[DI003141],
[DI000241],
[DI000242],
[DI000246],
[DI001591]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

GO

CREATE NONCLUSTERED INDEX [FK_DT407_TYPE] ON [dbo].[DT412] 
(
	[DI003141] ASC
)
INCLUDE ( [DI000238],
[DI000239],
[DI000252],
[DI000242],
[DI000246],
[DI001591]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

GO

CREATE NONCLUSTERED INDEX [FK_DT415_DT] ON [dbo].[DT412] 
(
	[DI000239] ASC
)
INCLUDE ( [DI000238],
[DI000252],
[DI003141],
[DI000242],
[DI000246],
[DI001591]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

GO

CREATE NONCLUSTERED INDEX [FK_DT445_EXIT] ON [dbo].[DT412] 
(
	[DI000252] ASC
)
INCLUDE ( [DI000238],
[DI000239],
[DI003141],
[DI000242],
[DI000246],
[DI001591]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

GO

/* Boost performance (WI 13952) */

CREATE INDEX "DT412_DATAITEM_ENABLED" ON "DT412" ("DI000238", "DI000239", "DI000252", "ENABLED", "UUID" ASC)

GO
