CREATE TABLE [dbo].[journal_accountings] (
   [subsidiary_to_company_ref] [bigint] NOT NULL,
   [accounting_date] [datetime] NOT NULL,
   [document_type] [varchar](100) NOT NULL,
   [document_number] [bigint] NOT NULL,
   [position_in_document] [bigint] NOT NULL,
   [customer_number] [bigint] NULL,
   [nominal_account_number] [bigint] NULL,
   [is_balanced] [varchar](100) NULL,
   [clearing_number] [bigint] NULL,
   [document_date] [datetime] NULL,
   [posted_value] [bigint] NULL,
   [debit_or_credit] [varchar](100) NULL,
   [posted_count] [bigint] NULL,
   [branch_number] [bigint] NULL,
   [customer_contra_account] [bigint] NULL,
   [nominal_contra_account] [bigint] NULL,
   [contra_account_text] [varchar](100) NULL,
   [account_form_page_number] [bigint] NULL,
   [account_form_page_line] [bigint] NULL,
   [serial_number_each_month] [varchar](50) NULL,
   [employee_number] [bigint] NULL,
   [invoice_date] [varchar](50) NULL,
   [invoice_number] [varchar](100) NULL,
   [dunning_level] [varchar](100) NULL,
   [last_dunning_date] [varchar](50) NULL,
   [journal_page] [bigint] NULL,
   [journal_line] [bigint] NULL,
   [cash_discount] [bigint] NULL,
   [term_of_payment] [bigint] NULL,
   [posting_text] [varchar](100) NOT NULL
      CONSTRAINT [DF_journal_accountings_posting_text] DEFAULT (''),
   [vehicle_reference] [varchar](100) NULL,
   [vat_id_number] [varchar](100) NULL,
   [account_statement_number] [bigint] NULL,
   [account_statement_page] [bigint] NULL,
   [vat_key] [varchar](100) NULL,
   [days_for_cash_discount] [bigint] NULL,
   [day_of_actual_accounting] [varchar](50) NULL,
   [skr51_branch] [bigint] NULL,
   [skr51_make] [bigint] NULL,
   [skr51_cost_center] [bigint] NULL,
   [skr51_sales_channel] [bigint] NULL,
   [skr51_cost_unit] [bigint] NULL,
   [previously_used_account_no] [varchar](100) NULL,
   [free_form_accounting_text] [varchar](255) NULL,
   [free_form_document_text] [varchar](255) NULL,
   [client_db] [varchar](20) NOT NULL

   ,CONSTRAINT [journal_accountings$0] PRIMARY KEY CLUSTERED ([subsidiary_to_company_ref], [accounting_date], [document_type], [document_number], [position_in_document], [client_db])
)

CREATE NONCLUSTERED INDEX [journal_accountings_nominal_account_number_index] ON [dbo].[journal_accountings] ([nominal_account_number]) INCLUDE ([posted_value], [debit_or_credit], [branch_number], [invoice_number], [skr51_branch], [skr51_make], [skr51_cost_center], [skr51_sales_channel], [skr51_cost_unit])
CREATE NONCLUSTERED INDEX [journal_accountings_posting_text_index] ON [dbo].[journal_accountings] ([posting_text]) INCLUDE ([nominal_account_number], [posted_value], [debit_or_credit], [posted_count], [employee_number], [invoice_date], [invoice_number], [vehicle_reference], [skr51_branch], [skr51_make], [skr51_cost_center], [skr51_sales_channel], [skr51_cost_unit])
CREATE NONCLUSTERED INDEX [journal_accountings_subsidiary_to_company_ref_nominal_account_number_index] ON [dbo].[journal_accountings] ([subsidiary_to_company_ref], [nominal_account_number]) INCLUDE ([posted_value], [debit_or_credit], [posted_count], [employee_number], [invoice_date], [invoice_number], [posting_text], [vehicle_reference], [skr51_branch], [skr51_make], [skr51_cost_center], [skr51_sales_channel], [skr51_cost_unit])

GO
