CREATE TABLE [import].[UNIT_HISTORY] (
   [UNIT_NUMBER] [varchar](10) NOT NULL,
   [LINE_TYPE] [char](2) NOT NULL,
   [LINE_NO] [numeric](4,0) NOT NULL,
   [STATE_CODE_UNIT] [char](1) NOT NULL,
   [TRANSACT_DATE] [datetime] NOT NULL,
   [HANDLER] [char](4) NOT NULL,
   [PROGRAM] [char](6) NOT NULL,
   [FUNCTION_CODE] [char](4) NOT NULL,
   [DOCUMENT_DATE] [datetime] NOT NULL,
   [DOCUMENT_NR] [numeric](15,0) NOT NULL,
   [ORDER_DATE] [datetime] NOT NULL,
   [ORDER_NUMBER] [numeric](15,0) NOT NULL,
   [TRANSACTION_CODE] [varchar](12) NOT NULL,
   [TAX_CODE] [char](1) NOT NULL,
   [REFERENCE] [varchar](255) NOT NULL,
   [COSTS] [numeric](15,2) NOT NULL,
   [PURCH_TAX] [numeric](15,2) NOT NULL,
   [ORDERS_GROSSVALUE] [numeric](15,2) NOT NULL,
   [TAX_SHARE] [numeric](15,2) NOT NULL,
   [DISCOUNT] [numeric](15,2) NOT NULL,
   [CLASSIFICATION_DTE] [datetime] NOT NULL,
   [BOOK_KEEPING_CODE] [varchar](10) NOT NULL,
   [TAX_HANDLING] [char](1) NOT NULL,
   [TRANSFER_TAX_PCT] [numeric](5,2) NOT NULL,
   [TRANSFER_DATE] [datetime] NOT NULL,
   [TRANSFER_SALES_TAX] [numeric](15,2) NOT NULL,
   [TRANSFER_PURCH_TAX] [numeric](15,2) NOT NULL,
   [DEPARTMENT] [char](4) NOT NULL,
   [BOOK_NO] [char](3) NULL,
   [PURCH_INVNO] [varchar](30) NULL,
   [BATCH_NUMBER_S] [numeric](7,0) NULL,
   [SETOFF_ACCT] [varchar](10) NULL,
   [INT_EXT_CODE] [char](1) NULL,
   [DESTINATION] [char](2) NULL,
   [OWN_DIMENSION_1] [varchar](30) NULL,
   [OWN_DIMENSION_2] [varchar](30) NULL,
   [OWN_DIMENSION_3] [varchar](30) NULL,
   [OWN_DIMENSION_4] [varchar](30) NULL,
   [OWN_DIMENSION_5] [varchar](30) NULL,
   [ACTIVITY] [char](2) NULL,
   [VAT_RATE_CODE] [char](2) NULL,
   [CALC_RULE_SYSTEM] [numeric](1,0) NULL,
   [ACC_AMOUNT_TYPE] [numeric](1,0) NULL,
   [TRANSACT_CODE_REV] [char](3) NULL,
   [INT_VOUCHER_NO] [numeric](15,0) NULL,
   [CONV_FLAG] [char](1) NULL,
   [timestamp] [binary](8) NOT NULL,
   [UNIQUE_IDENT] [numeric](12,0) NOT NULL,
   [CLIENT_DB] [varchar](20) NOT NULL

   ,CONSTRAINT [PKUNIT_HISTORY_UNIT_NUMBER] PRIMARY KEY CLUSTERED ([UNIT_NUMBER], [LINE_TYPE], [LINE_NO], [CLIENT_DB])
)

CREATE NONCLUSTERED INDEX [Unit_History_Transaction_Code] ON [import].[UNIT_HISTORY] ([TRANSACTION_CODE]) INCLUDE ([TRANSACT_DATE], [HANDLER], [PROGRAM], [FUNCTION_CODE], [DOCUMENT_DATE], [DOCUMENT_NR], [ORDER_DATE], [ORDER_NUMBER], [REFERENCE], [COSTS], [ORDERS_GROSSVALUE], [DISCOUNT], [CLASSIFICATION_DTE], [BOOK_KEEPING_CODE], [DEPARTMENT], [DESTINATION], [INT_VOUCHER_NO])

GO
