CREATE TABLE [dbo].[vehicles] (
   [internal_number] [int] NOT NULL,
   [vin] [varchar](50) NULL,
   [license_plate] [varchar](50) NULL,
   [license_plate_country] [varchar](10) NULL,
   [license_plate_season] [varchar](50) NULL,
   [make_number] [int] NULL,
   [free_form_make_text] [varchar](50) NULL,
   [model_code] [varchar](100) NULL,
   [free_form_model_text] [varchar](100) NULL,
   [is_roadworthy] [smallint] NULL,
   [is_customer_vehicle] [smallint] NULL,
   [dealer_vehicle_type] [varchar](10) NULL,
   [dealer_vehicle_number] [int] NULL,
   [first_registration_date] [varchar](50) NULL,
   [readmission_date] [varchar](50) NULL,
   [next_service_date] [varchar](50) NULL,
   [next_service_km] [int] NULL,
   [next_service_miles] [int] NULL,
   [production_year] [varchar](50) NULL,
   [owner_number] [int] NULL,
   [holder_number] [int] NULL,
   [previous_owner_number] [int] NULL,
   [previous_owner_counter] [int] NULL,
   [last_holder_change_date] [datetime] NULL,
   [german_kba_hsn] [varchar](50) NULL,
   [german_kba_tsn] [varchar](50) NULL,
   [austria_nat_code] [varchar](50) NULL,
   [is_prefer_km] [smallint] NULL,
   [mileage_km] [int] NULL,
   [mileage_miles] [int] NULL,
   [odometer_reading_date] [datetime] NULL,
   [engine_number] [varchar](100) NULL,
   [gear_number] [varchar](100) NULL,
   [unloaded_weight] [int] NULL,
   [gross_vehicle_weight] [int] NULL,
   [power_kw] [int] NULL,
   [cubic_capacity] [int] NULL,
   [is_all_accidents_repaired] [smallint] NULL,
   [accidents_counter] [int] NULL,
   [has_tyre_pressure_sensor] [smallint] NULL,
   [carkey_number] [varchar](50) NULL,
   [internal_source_flag] [varchar](10) NULL,
   [emission_code] [varchar](50) NULL,
   [first_sold_country] [varchar](10) NULL,
   [first_sold_dealer_code] [int] NULL,
   [body_paint_code] [varchar](100) NULL,
   [body_paint_description] [varchar](100) NULL,
   [is_body_paint_metallic] [smallint] NULL,
   [interior_paint_code] [varchar](100) NULL,
   [interior_paint_description] [varchar](100) NULL,
   [trim_code] [varchar](100) NULL,
   [trim_description] [varchar](100) NULL,
   [fine_dust_label] [varchar](10) NULL,
   [internal_assignment] [varchar](50) NULL,
   [ricambi_free_input] [varchar](100) NULL,
   [document_number] [varchar](50) NULL,
   [salesman_number] [int] NULL,
   [sale_date] [varchar](50) NULL,
   [next_emission_test_date] [datetime] NULL,
   [next_general_inspection_date] [datetime] NULL,
   [next_rust_inspection_date] [datetime] NULL,
   [next_exceptional_inspection_da] [datetime] NULL,
   [last_change_date] [datetime] NULL,
   [last_change_employee_no] [int] NULL,
   [created_date] [datetime] NULL,
   [created_employee_no] [int] NULL,
   [subsidiary] [int] NULL,
   [last_change_subsidiary] [int] NULL,
   [lock_by_workstation] [int] NULL,
   [lock_time] [datetime] NULL,
   [lock_trace] [varchar](255) NULL,
   [lock_trigger] [varchar](255) NULL,
   [lock_by_employee] [int] NULL,
   [lock_sourcecode] [varchar](255) NULL,
   [client_db] [varchar](20) NOT NULL

   ,CONSTRAINT [vehicles$0] PRIMARY KEY CLUSTERED ([internal_number], [client_db])
)

CREATE NONCLUSTERED INDEX [vehicles_vin_index] ON [dbo].[vehicles] ([vin]) INCLUDE ([make_number], [model_code], [owner_number], [holder_number], [salesman_number])

GO
