
/* drop existing PK constraint, indexes */

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

GO

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

GO

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

CREATE UNIQUE CLUSTERED INDEX [DT420_SCHEMA_DT415_DT] ON [dbo].[DT415] 
(
	[DI000266] ASC,
	[DI000265] 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].[DT415] ADD  CONSTRAINT [PK_DT415_DT] PRIMARY KEY NONCLUSTERED 
(
	[DI000265] 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 NONCLUSTERED INDEX [FK_DT420_SCHEMA] ON [dbo].[DT415] 
(
	[DI000266] ASC
)
INCLUDE ( [DI000265]) 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 UNIQUE NONCLUSTERED INDEX [ENTITYNAMEUNIQUE]
ON [DT415] (ENTITYNAME)
WHERE [ENTITYNAME] IS NOT NULL

GO

/* Boost performance (WI 13952) */

CREATE INDEX "DT415_TABLE_ENABLED" ON "DT415" ("DI000265", "ENABLED", "UUID" ASC)

GO

CREATE UNIQUE INDEX "UUID_DI_UNIQUE" ON "DT415" ("UUID_DI") WHERE "UUID_DI" IS NOT NULL

GO
