CREATE TABLE [dbo].[AlertEvent]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[AlertDefID] [int] NOT NULL,
[DeviceID] [int] NOT NULL,
[ConsumableHashCode] [int] NULL,
[FirstReceived] [datetime] NOT NULL,
[LastReceived] [datetime] NULL,
[FirstTriggeredValue] [float] NULL,
[LastTriggeredValue] [float] NULL,
[EstimatedOverdueDate] [datetime] NOT NULL,
[EstimatedStaleDate] [datetime] NOT NULL,
[IsOverdue] [bit] NOT NULL CONSTRAINT [DF_AlertEvent_IsOverdue] DEFAULT ((0)),
[IsArchived] [bit] NOT NULL CONSTRAINT [DF_AlertEvent_IsArchived] DEFAULT ((0)),
[IsIgnored] [bit] NOT NULL CONSTRAINT [DF_AlertEvent_IsIgnored] DEFAULT ((0)),
[ConsumableTypeExtended] [smallint] NULL CONSTRAINT [DF_AlertEvent_ConsumableTypeExtended] DEFAULT ((0)),
[ConsumableSerialNumber] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[EventType] [smallint] NOT NULL,
[ServiceErrorState] [int] NULL,
[ServiceErrorCategory] [smallint] NULL,
[FirstConsoleMessage] [nvarchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[FirstPageCountTotal] [int] NULL,
[LastConsoleMessage] [nvarchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LastPageCountTotal] [int] NULL,
[Updates] [int] NULL,
[AlertIndex] [int] NULL,
[AlertSeverityLevel] [int] NULL,
[AlertTrainingLevel] [int] NULL,
[AlertGroup] [int] NULL,
[AlertGroupIndex] [int] NULL,
[AlertLocation] [int] NULL,
[AlertCode] [int] NULL,
[AlertDescription] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[AlertTime] [datetime] NULL,
[ActivatedOnAuditID] [int] NULL,
[AlertHashCode] [int] NULL,
[ArchivedDate] [datetime] NULL,
[ArchivedReason] [smallint] NULL,
[IsNormalizedSupply] [bit] NULL CONSTRAINT [DF_AlertEvent_IsNormalizedSupply] DEFAULT ((0)),
[TriggerType] [smallint] NOT NULL CONSTRAINT [DF_AlertEvent_TriggerType] DEFAULT ((0))
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[AlertEvent] ADD CONSTRAINT [PK_AlertEvent_ID] PRIMARY KEY CLUSTERED ([ID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[AlertEvent] ADD CONSTRAINT [FK_AlertEvent_AlertDefID_AlertDefinition_ID] FOREIGN KEY ([AlertDefID]) REFERENCES [dbo].[AlertDefinition] ([ID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[AlertEvent] ADD CONSTRAINT [FK_AlertEvent_DeviceID_Device_DeviceID] FOREIGN KEY ([DeviceID]) REFERENCES [dbo].[Device] ([DeviceID])
GO