CREATE TABLE [dbo].[ba_batches]
(
[ba_batch_id] [int] NOT NULL,
[ba_user_code] [dbo].[ais_code_medium] NOT NULL,
[ba_start_date] [datetime] NOT NULL,
[ba_end_date] [datetime] NULL,
[ba_batch_status] [dbo].[ais_code_medium] NOT NULL,
[ba_type] [varchar] (50) COLLATE French_CI_AS NOT NULL,
[ba_params] [varchar] (4000) COLLATE French_CI_AS NULL,
[ba_params_checksum] AS (checksum([ba_params])),
[ba_error_message] [nvarchar] (2000) COLLATE French_CI_AS NULL,
[ba_error_stacktrace] [varchar] (4000) COLLATE French_CI_AS NULL
) ON [PRIMARY]
ALTER TABLE [dbo].[ba_batches] ADD 
CONSTRAINT [PK_bo_batches] PRIMARY KEY CLUSTERED  ([ba_batch_id]) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [IX_bo_batches_type] ON [dbo].[ba_batches] ([ba_type]) ON [PRIMARY]

CREATE NONCLUSTERED INDEX [IX_bo_batches_checksum] ON [dbo].[ba_batches] ([ba_params_checksum]) ON [PRIMARY]

GO

ALTER TABLE [dbo].[ba_batches] ADD CONSTRAINT [FK_ba_batches_nm_batches_statuses] FOREIGN KEY ([ba_batch_status]) REFERENCES [dbo].[nm_batches_statuses] ([nmbs_batch_status_code])
GO
