CREATE TABLE [dbo].[CrewSMSActivity]
(
[CrewSMSActivityID] [int] NOT NULL IDENTITY(1, 1),
[SakariContactFID] [int] NOT NULL,
[LocServFID] [int] NOT NULL,
[SysuserFID] [int] NOT NULL,
[LastOutgoingMessageSentAt] [datetimeoffset] NOT NULL,
[SakariIncomingMessageFID] [int] NULL,
[SakariOutgoingMessageFID] [int] NULL,
[RemovedFromServiceMessageSent] [bit] NOT NULL CONSTRAINT [DF_CrewSMSActivity_RemovedFromServiceMessage] DEFAULT ((0)),
[IsResend] [bit] NOT NULL CONSTRAINT [DF_CrewSMSActivity_IsResend] DEFAULT ((0))
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[CrewSMSActivity] ADD CONSTRAINT [PK_CrewSMSActivity] PRIMARY KEY NONCLUSTERED ([CrewSMSActivityID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_CrewSMSActivity_LastOutgoingMessageSentAt] ON [dbo].[CrewSMSActivity] ([LastOutgoingMessageSentAt]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_CrewSMSActivity_LocServFID_SysuserFID_SakariContactFID] ON [dbo].[CrewSMSActivity] ([LocServFID], [SysuserFID], [SakariContactFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[CrewSMSActivity] ADD CONSTRAINT [FK_CrewSMSActivity_LocServ] FOREIGN KEY ([LocServFID]) REFERENCES [dbo].[LocServ] ([PriKey])
GO
ALTER TABLE [dbo].[CrewSMSActivity] ADD CONSTRAINT [FK_CrewSMSActivity_SakariContact] FOREIGN KEY ([SakariContactFID]) REFERENCES [dbo].[SakariContact] ([SakariContactID])
GO
ALTER TABLE [dbo].[CrewSMSActivity] ADD CONSTRAINT [FK_CrewSMSActivity_SakariIncomingMessage] FOREIGN KEY ([SakariIncomingMessageFID]) REFERENCES [dbo].[SakariIncomingMessage] ([SakariIncomingMessageID])
GO
ALTER TABLE [dbo].[CrewSMSActivity] ADD CONSTRAINT [FK_CrewSMSActivity_SakariOutgoingMessage] FOREIGN KEY ([SakariOutgoingMessageFID]) REFERENCES [dbo].[SakariOutgoingMessage] ([SakariOutgoingMessageID])
GO
ALTER TABLE [dbo].[CrewSMSActivity] ADD CONSTRAINT [FK_CrewSMSActivity_Sysuser] FOREIGN KEY ([SysuserFID]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
GRANT SELECT ON [dbo].[CrewSMSActivity] TO [MssExec]
GRANT INSERT ON [dbo].[CrewSMSActivity] TO [MssExec]
GRANT DELETE ON [dbo].[CrewSMSActivity] TO [MssExec]
GRANT UPDATE ON [dbo].[CrewSMSActivity] TO [MssExec]
GO