CREATE TABLE [dbo].[ToDo]
(
[ToDoID] [int] NOT NULL IDENTITY(1, 1),
[RolloutID] [int] NULL,
[ProfileID] [int] NOT NULL,
[TaskID] [int] NOT NULL,
[UserID] [int] NULL,
[DateTimeStamp] [datetime] NULL,
[Complete] [tinyint] NOT NULL CONSTRAINT [DF_ToDo_Complete] DEFAULT ((0)),
[OrderID] [int] NULL,
[CompletedBy] [int] NULL,
[DateTimeCompleted] [datetime] NULL,
[OpenUserFlag] [bit] NOT NULL CONSTRAINT [DF_ToDo_OpenUserFlag] DEFAULT ((0)),
[NotApplicableFlag] [bit] NOT NULL CONSTRAINT [DF_ToDo_NotApplicableFlag] DEFAULT ((0)),
[NotApplicableSysUserFID] [int] NULL,
[NotApplicableDateTime] [datetime] NULL,
[Identifier] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_ToDo_Identifier] DEFAULT (''),
[OriginalDueDate] [datetime] NULL,
[TaskChangedOnDate] [datetime] NULL,
[TaskChangedBySysUserFID] [int] NULL,
[DueDateWhenDischarged] [datetime] NULL,
[CreatedBySysuserFID] [int] NULL,
[DependencyDateID] [int] NULL,
[DueDays] [int] NULL,
[DueType] [int] NULL,
[DueDate] [datetime] NULL,
[TaskUserFID] [int] NULL,
[TaskPriorityFID] [int] NULL,
[CoordinatorTypeFID] [int] NULL,
[DependencyTaskFID] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ToDo] ADD CONSTRAINT [PK_TODO] PRIMARY KEY CLUSTERED ([ToDoID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ToDo_CompletedBy] ON [dbo].[ToDo] ([CompletedBy]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ToDo_CreatedBySysuserFID] ON [dbo].[ToDo] ([CreatedBySysuserFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ToDo_NotApplicableSysUserFID] ON [dbo].[ToDo] ([NotApplicableSysUserFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ToDo_OrderID_Identifier] ON [dbo].[ToDo] ([OrderID], [Identifier]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ToDo_ProfileID] ON [dbo].[ToDo] ([ProfileID]) INCLUDE ([Complete], [CompletedBy], [CreatedBySysuserFID], [DateTimeCompleted], [DateTimeStamp], [DueDate], [DueDays], [DueType], [Identifier], [NotApplicableDateTime], [NotApplicableFlag], [NotApplicableSysUserFID], [OrderID], [OriginalDueDate], [RolloutID], [TaskChangedBySysUserFID], [TaskChangedOnDate], [TaskID], [TaskUserFID], [ToDoID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ToDo_RolloutID] ON [dbo].[ToDo] ([RolloutID], [Complete], [NotApplicableFlag], [DueDate]) INCLUDE ([CompletedBy], [CreatedBySysuserFID], [DateTimeCompleted], [DateTimeStamp], [DueDays], [DueType], [Identifier], [NotApplicableDateTime], [NotApplicableSysUserFID], [OrderID], [OriginalDueDate], [ProfileID], [TaskChangedBySysUserFID], [TaskChangedOnDate], [TaskID], [TaskUserFID], [ToDoID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ToDo_TaskChangedBySysUserFID] ON [dbo].[ToDo] ([TaskChangedBySysUserFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ToDo_TaskID] ON [dbo].[ToDo] ([TaskID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ToDo_TaskUserFID_DueDate] ON [dbo].[ToDo] ([TaskUserFID], [Complete], [NotApplicableFlag], [DueDate]) INCLUDE ([CompletedBy], [CreatedBySysuserFID], [DateTimeCompleted], [DateTimeStamp], [DueDays], [DueType], [Identifier], [NotApplicableDateTime], [NotApplicableSysUserFID], [OrderID], [OriginalDueDate], [ProfileID], [RolloutID], [TaskChangedBySysUserFID], [TaskChangedOnDate], [TaskID], [ToDoID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ToDo_CompleteNotApplicable] ON [dbo].[ToDo] ([TaskUserFID], [Complete], [NotApplicableFlag], [DueDate]) INCLUDE ([CompletedBy], [CreatedBySysuserFID], [DateTimeCompleted], [DateTimeStamp], [DependencyDateID], [DueDays], [DueType], [Identifier], [OpenUserFlag], [OrderID], [OriginalDueDate], [ProfileID], [RolloutID], [TaskChangedBySysUserFID], [TaskChangedOnDate], [TaskID], [ToDoID], [UserID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ToDo_UserID] ON [dbo].[ToDo] ([UserID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ToDo] ADD CONSTRAINT [FK_TODO_Sysuser1] FOREIGN KEY ([CompletedBy]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[ToDo] ADD CONSTRAINT [FK_TODO_Sysuser4] FOREIGN KEY ([CreatedBySysuserFID]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[ToDo] ADD CONSTRAINT [FK_ToDo_SysUser2] FOREIGN KEY ([NotApplicableSysUserFID]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[ToDo] ADD CONSTRAINT [FK_TODO_ORDERS] FOREIGN KEY ([OrderID]) REFERENCES [dbo].[Orders] ([PriKey])
GO
ALTER TABLE [dbo].[ToDo] ADD CONSTRAINT [FK_TODO_PROFILES] FOREIGN KEY ([ProfileID]) REFERENCES [dbo].[Profiles] ([ProfileID])
GO
ALTER TABLE [dbo].[ToDo] ADD CONSTRAINT [FK_TODO_ROLLOUTS] FOREIGN KEY ([RolloutID]) REFERENCES [dbo].[RollOuts] ([RollOutID])
GO
ALTER TABLE [dbo].[ToDo] ADD CONSTRAINT [FK_ToDo_SysUser3] FOREIGN KEY ([TaskChangedBySysUserFID]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[ToDo] ADD CONSTRAINT [FK_TODO_TASKS] FOREIGN KEY ([TaskID]) REFERENCES [dbo].[Tasks] ([TaskID])
GO
ALTER TABLE [dbo].[ToDo] ADD CONSTRAINT [FK_ToDo_TaskPriority] FOREIGN KEY ([TaskPriorityFID]) REFERENCES [dbo].[TaskPriority] ([TaskPriorityID])
GO
ALTER TABLE [dbo].[ToDo] ADD CONSTRAINT [FK_TODO_Sysuser] FOREIGN KEY ([UserID]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
GRANT SELECT ON [dbo].[ToDo] TO [MssExec]
GRANT INSERT ON [dbo].[ToDo] TO [MssExec]
GRANT DELETE ON [dbo].[ToDo] TO [MssExec]
GRANT UPDATE ON [dbo].[ToDo] TO [MssExec]
GO