SCHEMA PREVIEW
SERVICE_SALE_ORDER_LINE
Xem trước DDL trước khi tạo hoặc bổ sung cột an toàn trên SQL Server.
SQL Server DDL
Chỉ tự động tạo schema/table/index và thêm cột nullable còn thiếu.
IF SCHEMA_ID(N'stg') IS NULL EXEC(N'CREATE SCHEMA [stg]');
IF SCHEMA_ID(N'ods') IS NULL EXEC(N'CREATE SCHEMA [ods]');
IF SCHEMA_ID(N'hist') IS NULL EXEC(N'CREATE SCHEMA [hist]');
IF OBJECT_ID(N'stg.J10_sale_order_line', N'U') IS NULL
BEGIN
CREATE TABLE [stg].[J10_sale_order_line]
(
[id] int NULL,
[order_id] int NULL,
[sequence] int NULL,
[company_id] int NULL,
[currency_id] int NULL,
[order_partner_id] int NULL,
[salesman_id] int NULL,
[product_id] int NULL,
[product_uom] int NULL,
[product_packaging_id] int NULL,
[create_uid] int NULL,
[write_uid] int NULL,
[state] nvarchar(max) NULL,
[display_type] nvarchar(max) NULL,
[qty_delivered_method] nvarchar(max) NULL,
[invoice_status] nvarchar(max) NULL,
[analytic_distribution] nvarchar(max) NULL,
[name] nvarchar(max) NULL,
[product_uom_qty] decimal(38,10) NULL,
[price_unit] decimal(38,10) NULL,
[discount] decimal(38,10) NULL,
[price_subtotal] decimal(38,10) NULL,
[price_total] decimal(38,10) NULL,
[price_reduce_taxexcl] decimal(38,10) NULL,
[price_reduce_taxinc] decimal(38,10) NULL,
[qty_delivered] decimal(38,10) NULL,
[qty_invoiced] decimal(38,10) NULL,
[qty_to_invoice] decimal(38,10) NULL,
[untaxed_amount_invoiced] decimal(38,10) NULL,
[untaxed_amount_to_invoice] decimal(38,10) NULL,
[is_downpayment] bit NULL,
[is_expense] bit NULL,
[create_date] datetime2(6) NULL,
[write_date] datetime2(6) NULL,
[price_tax] float NULL,
[product_packaging_qty] float NULL,
[customer_lead] float NULL,
[sap_wmonth] int NULL,
[sap_is_discount] nvarchar(max) NULL,
[route_id] int NULL,
[onhand_quantity] float NULL,
[filler_warehouse_id] int NULL,
[create_sap] bit NULL,
[ts_supply_side] nvarchar(max) NULL,
[lt_side_qty] float NULL,
[lt_lt_qty] float NULL,
[lt_main_qty] float NULL,
[ts_alloc_main_qty] float NULL,
[ts_alloc_lt_qty] float NULL,
[lt_warehouse_code] nvarchar(max) NULL,
[manufacturer_warranty_month] int NULL,
[sap_dxvt_created] bit NULL,
[ts_source_order_id] int NULL,
[ts_source_ticket_id] int NULL,
[quotation_warranty_term] nvarchar(max) NULL,
[sync_source_id] int NOT NULL,
[sync_job_id] int NOT NULL,
[sync_run_id] bigint NOT NULL,
[sync_row_hash] varbinary(32) NOT NULL,
[sync_is_deleted] bit NOT NULL,
[sync_created_at] datetime2(7) NOT NULL,
[sync_updated_at] datetime2(7) NOT NULL
);
END;
IF OBJECT_ID(N'ods.sale_order_line', N'U') IS NULL
BEGIN
CREATE TABLE [ods].[sale_order_line]
(
[id] int NOT NULL,
[order_id] int NOT NULL,
[sequence] int NULL,
[company_id] int NULL,
[currency_id] int NULL,
[order_partner_id] int NULL,
[salesman_id] int NULL,
[product_id] int NULL,
[product_uom] int NULL,
[product_packaging_id] int NULL,
[create_uid] int NULL,
[write_uid] int NULL,
[state] nvarchar(max) NULL,
[display_type] nvarchar(max) NULL,
[qty_delivered_method] nvarchar(max) NULL,
[invoice_status] nvarchar(max) NULL,
[analytic_distribution] nvarchar(max) NULL,
[name] nvarchar(max) NOT NULL,
[product_uom_qty] decimal(38,10) NOT NULL,
[price_unit] decimal(38,10) NOT NULL,
[discount] decimal(38,10) NULL,
[price_subtotal] decimal(38,10) NULL,
[price_total] decimal(38,10) NULL,
[price_reduce_taxexcl] decimal(38,10) NULL,
[price_reduce_taxinc] decimal(38,10) NULL,
[qty_delivered] decimal(38,10) NULL,
[qty_invoiced] decimal(38,10) NULL,
[qty_to_invoice] decimal(38,10) NULL,
[untaxed_amount_invoiced] decimal(38,10) NULL,
[untaxed_amount_to_invoice] decimal(38,10) NULL,
[is_downpayment] bit NULL,
[is_expense] bit NULL,
[create_date] datetime2(6) NULL,
[write_date] datetime2(6) NULL,
[price_tax] float NULL,
[product_packaging_qty] float NULL,
[customer_lead] float NOT NULL,
[sap_wmonth] int NULL,
[sap_is_discount] nvarchar(max) NOT NULL,
[route_id] int NULL,
[onhand_quantity] float NULL,
[filler_warehouse_id] int NULL,
[create_sap] bit NULL,
[ts_supply_side] nvarchar(max) NULL,
[lt_side_qty] float NULL,
[lt_lt_qty] float NULL,
[lt_main_qty] float NULL,
[ts_alloc_main_qty] float NULL,
[ts_alloc_lt_qty] float NULL,
[lt_warehouse_code] nvarchar(max) NULL,
[manufacturer_warranty_month] int NULL,
[sap_dxvt_created] bit NULL,
[ts_source_order_id] int NULL,
[ts_source_ticket_id] int NULL,
[quotation_warranty_term] nvarchar(max) NULL,
[sync_source_id] int NOT NULL,
[sync_job_id] int NOT NULL,
[sync_run_id] bigint NOT NULL,
[sync_row_hash] varbinary(32) NOT NULL,
[sync_is_deleted] bit NOT NULL CONSTRAINT [DF_sale_order_line_IsDeleted] DEFAULT (0),
[sync_created_at] datetime2(7) NOT NULL,
[sync_updated_at] datetime2(7) NOT NULL,
CONSTRAINT [PK_sale_order_line] PRIMARY KEY ([sync_source_id], [id])
);
END;
IF OBJECT_ID(N'hist.J10_sale_order_line_History', N'U') IS NULL
BEGIN
CREATE TABLE [hist].[J10_sale_order_line_History]
(
[history_id] bigint IDENTITY(1,1) NOT NULL PRIMARY KEY,
[source_record_id] nvarchar(450) NOT NULL,
[id] int NULL,
[order_id] int NULL,
[sequence] int NULL,
[company_id] int NULL,
[currency_id] int NULL,
[order_partner_id] int NULL,
[salesman_id] int NULL,
[product_id] int NULL,
[product_uom] int NULL,
[product_packaging_id] int NULL,
[create_uid] int NULL,
[write_uid] int NULL,
[state] nvarchar(max) NULL,
[display_type] nvarchar(max) NULL,
[qty_delivered_method] nvarchar(max) NULL,
[invoice_status] nvarchar(max) NULL,
[analytic_distribution] nvarchar(max) NULL,
[name] nvarchar(max) NULL,
[product_uom_qty] decimal(38,10) NULL,
[price_unit] decimal(38,10) NULL,
[discount] decimal(38,10) NULL,
[price_subtotal] decimal(38,10) NULL,
[price_total] decimal(38,10) NULL,
[price_reduce_taxexcl] decimal(38,10) NULL,
[price_reduce_taxinc] decimal(38,10) NULL,
[qty_delivered] decimal(38,10) NULL,
[qty_invoiced] decimal(38,10) NULL,
[qty_to_invoice] decimal(38,10) NULL,
[untaxed_amount_invoiced] decimal(38,10) NULL,
[untaxed_amount_to_invoice] decimal(38,10) NULL,
[is_downpayment] bit NULL,
[is_expense] bit NULL,
[create_date] datetime2(6) NULL,
[write_date] datetime2(6) NULL,
[price_tax] float NULL,
[product_packaging_qty] float NULL,
[customer_lead] float NULL,
[sap_wmonth] int NULL,
[sap_is_discount] nvarchar(max) NULL,
[route_id] int NULL,
[onhand_quantity] float NULL,
[filler_warehouse_id] int NULL,
[create_sap] bit NULL,
[ts_supply_side] nvarchar(max) NULL,
[lt_side_qty] float NULL,
[lt_lt_qty] float NULL,
[lt_main_qty] float NULL,
[ts_alloc_main_qty] float NULL,
[ts_alloc_lt_qty] float NULL,
[lt_warehouse_code] nvarchar(max) NULL,
[manufacturer_warranty_month] int NULL,
[sap_dxvt_created] bit NULL,
[ts_source_order_id] int NULL,
[ts_source_ticket_id] int NULL,
[quotation_warranty_term] nvarchar(max) NULL,
[sync_source_id] int NOT NULL,
[sync_job_id] int NOT NULL,
[sync_run_id] bigint NOT NULL,
[valid_from] datetime2(7) NOT NULL,
[valid_to] datetime2(7) NULL,
[is_current] bit NOT NULL,
[row_hash] varbinary(32) NOT NULL,
[source_updated_at] datetimeoffset(7) NOT NULL,
[sync_is_deleted] bit NOT NULL
);
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'id') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [id] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'id') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [id] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'id') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [id] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'order_id') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [order_id] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'order_id') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [order_id] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'order_id') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [order_id] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'sequence') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [sequence] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'sequence') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [sequence] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'sequence') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [sequence] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'company_id') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [company_id] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'company_id') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [company_id] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'company_id') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [company_id] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'currency_id') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [currency_id] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'currency_id') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [currency_id] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'currency_id') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [currency_id] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'order_partner_id') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [order_partner_id] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'order_partner_id') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [order_partner_id] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'order_partner_id') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [order_partner_id] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'salesman_id') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [salesman_id] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'salesman_id') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [salesman_id] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'salesman_id') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [salesman_id] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'product_id') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [product_id] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'product_id') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [product_id] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'product_id') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [product_id] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'product_uom') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [product_uom] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'product_uom') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [product_uom] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'product_uom') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [product_uom] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'product_packaging_id') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [product_packaging_id] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'product_packaging_id') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [product_packaging_id] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'product_packaging_id') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [product_packaging_id] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'create_uid') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [create_uid] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'create_uid') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [create_uid] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'create_uid') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [create_uid] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'write_uid') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [write_uid] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'write_uid') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [write_uid] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'write_uid') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [write_uid] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'state') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [state] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'state') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [state] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'state') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [state] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'display_type') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [display_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'display_type') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [display_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'display_type') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [display_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'qty_delivered_method') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [qty_delivered_method] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'qty_delivered_method') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [qty_delivered_method] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'qty_delivered_method') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [qty_delivered_method] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'invoice_status') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [invoice_status] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'invoice_status') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [invoice_status] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'invoice_status') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [invoice_status] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'analytic_distribution') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [analytic_distribution] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'analytic_distribution') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [analytic_distribution] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'analytic_distribution') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [analytic_distribution] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'name') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [name] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'name') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [name] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'name') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [name] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'product_uom_qty') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [product_uom_qty] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'product_uom_qty') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [product_uom_qty] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'product_uom_qty') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [product_uom_qty] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'price_unit') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [price_unit] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'price_unit') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [price_unit] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'price_unit') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [price_unit] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'discount') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [discount] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'discount') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [discount] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'discount') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [discount] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'price_subtotal') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [price_subtotal] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'price_subtotal') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [price_subtotal] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'price_subtotal') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [price_subtotal] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'price_total') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [price_total] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'price_total') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [price_total] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'price_total') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [price_total] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'price_reduce_taxexcl') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [price_reduce_taxexcl] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'price_reduce_taxexcl') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [price_reduce_taxexcl] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'price_reduce_taxexcl') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [price_reduce_taxexcl] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'price_reduce_taxinc') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [price_reduce_taxinc] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'price_reduce_taxinc') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [price_reduce_taxinc] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'price_reduce_taxinc') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [price_reduce_taxinc] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'qty_delivered') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [qty_delivered] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'qty_delivered') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [qty_delivered] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'qty_delivered') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [qty_delivered] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'qty_invoiced') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [qty_invoiced] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'qty_invoiced') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [qty_invoiced] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'qty_invoiced') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [qty_invoiced] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'qty_to_invoice') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [qty_to_invoice] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'qty_to_invoice') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [qty_to_invoice] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'qty_to_invoice') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [qty_to_invoice] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'untaxed_amount_invoiced') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [untaxed_amount_invoiced] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'untaxed_amount_invoiced') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [untaxed_amount_invoiced] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'untaxed_amount_invoiced') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [untaxed_amount_invoiced] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'untaxed_amount_to_invoice') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [untaxed_amount_to_invoice] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'untaxed_amount_to_invoice') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [untaxed_amount_to_invoice] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'untaxed_amount_to_invoice') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [untaxed_amount_to_invoice] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'is_downpayment') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [is_downpayment] bit NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'is_downpayment') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [is_downpayment] bit NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'is_downpayment') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [is_downpayment] bit NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'is_expense') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [is_expense] bit NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'is_expense') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [is_expense] bit NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'is_expense') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [is_expense] bit NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'create_date') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [create_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'create_date') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [create_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'create_date') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [create_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'write_date') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [write_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'write_date') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [write_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'write_date') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [write_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'price_tax') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [price_tax] float NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'price_tax') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [price_tax] float NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'price_tax') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [price_tax] float NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'product_packaging_qty') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [product_packaging_qty] float NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'product_packaging_qty') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [product_packaging_qty] float NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'product_packaging_qty') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [product_packaging_qty] float NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'customer_lead') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [customer_lead] float NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'customer_lead') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [customer_lead] float NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'customer_lead') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [customer_lead] float NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'sap_wmonth') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [sap_wmonth] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'sap_wmonth') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [sap_wmonth] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'sap_wmonth') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [sap_wmonth] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'sap_is_discount') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [sap_is_discount] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'sap_is_discount') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [sap_is_discount] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'sap_is_discount') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [sap_is_discount] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'route_id') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [route_id] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'route_id') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [route_id] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'route_id') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [route_id] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'onhand_quantity') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [onhand_quantity] float NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'onhand_quantity') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [onhand_quantity] float NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'onhand_quantity') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [onhand_quantity] float NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'filler_warehouse_id') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [filler_warehouse_id] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'filler_warehouse_id') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [filler_warehouse_id] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'filler_warehouse_id') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [filler_warehouse_id] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'create_sap') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [create_sap] bit NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'create_sap') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [create_sap] bit NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'create_sap') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [create_sap] bit NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'ts_supply_side') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [ts_supply_side] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'ts_supply_side') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [ts_supply_side] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'ts_supply_side') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [ts_supply_side] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'lt_side_qty') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [lt_side_qty] float NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'lt_side_qty') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [lt_side_qty] float NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'lt_side_qty') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [lt_side_qty] float NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'lt_lt_qty') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [lt_lt_qty] float NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'lt_lt_qty') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [lt_lt_qty] float NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'lt_lt_qty') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [lt_lt_qty] float NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'lt_main_qty') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [lt_main_qty] float NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'lt_main_qty') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [lt_main_qty] float NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'lt_main_qty') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [lt_main_qty] float NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'ts_alloc_main_qty') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [ts_alloc_main_qty] float NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'ts_alloc_main_qty') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [ts_alloc_main_qty] float NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'ts_alloc_main_qty') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [ts_alloc_main_qty] float NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'ts_alloc_lt_qty') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [ts_alloc_lt_qty] float NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'ts_alloc_lt_qty') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [ts_alloc_lt_qty] float NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'ts_alloc_lt_qty') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [ts_alloc_lt_qty] float NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'lt_warehouse_code') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [lt_warehouse_code] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'lt_warehouse_code') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [lt_warehouse_code] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'lt_warehouse_code') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [lt_warehouse_code] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'manufacturer_warranty_month') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [manufacturer_warranty_month] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'manufacturer_warranty_month') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [manufacturer_warranty_month] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'manufacturer_warranty_month') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [manufacturer_warranty_month] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'sap_dxvt_created') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [sap_dxvt_created] bit NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'sap_dxvt_created') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [sap_dxvt_created] bit NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'sap_dxvt_created') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [sap_dxvt_created] bit NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'ts_source_order_id') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [ts_source_order_id] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'ts_source_order_id') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [ts_source_order_id] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'ts_source_order_id') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [ts_source_order_id] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'ts_source_ticket_id') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [ts_source_ticket_id] int NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'ts_source_ticket_id') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [ts_source_ticket_id] int NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'ts_source_ticket_id') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [ts_source_ticket_id] int NULL;
END;
IF COL_LENGTH(N'stg.J10_sale_order_line', N'quotation_warranty_term') IS NULL
BEGIN
ALTER TABLE [stg].[J10_sale_order_line] ADD [quotation_warranty_term] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.sale_order_line', N'quotation_warranty_term') IS NULL
BEGIN
ALTER TABLE [ods].[sale_order_line] ADD [quotation_warranty_term] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J10_sale_order_line_History', N'quotation_warranty_term') IS NULL
BEGIN
ALTER TABLE [hist].[J10_sale_order_line_History] ADD [quotation_warranty_term] nvarchar(max) NULL;
END;
IF NOT EXISTS
(
SELECT 1
FROM sys.indexes AS indexes
INNER JOIN sys.index_columns AS first_column
ON first_column.[object_id] = indexes.[object_id]
AND first_column.[index_id] = indexes.[index_id]
AND first_column.[key_ordinal] = 1
INNER JOIN sys.columns AS first_column_name
ON first_column_name.[object_id] = first_column.[object_id]
AND first_column_name.[column_id] = first_column.[column_id]
INNER JOIN sys.index_columns AS second_column
ON second_column.[object_id] = indexes.[object_id]
AND second_column.[index_id] = indexes.[index_id]
AND second_column.[key_ordinal] = 2
INNER JOIN sys.columns AS second_column_name
ON second_column_name.[object_id] = second_column.[object_id]
AND second_column_name.[column_id] = second_column.[column_id]
WHERE indexes.[object_id] = OBJECT_ID(N'ods.sale_order_line')
AND first_column_name.[name] = N'sync_source_id'
AND second_column_name.[name] = N'id'
)
CREATE INDEX [IX_sale_order_line_SyncSource_Key] ON [ods].[sale_order_line] ([sync_source_id], [id]);
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'ods.sale_order_line') AND name = N'IX_sale_order_line_UpdatedAt_Id')
CREATE INDEX [IX_sale_order_line_UpdatedAt_Id] ON [ods].[sale_order_line] ([write_date], [id]);
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'ods.sale_order_line') AND name = N'IX_sale_order_line_IsDeleted')
CREATE INDEX [IX_sale_order_line_IsDeleted] ON [ods].[sale_order_line] ([sync_is_deleted]);
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'hist.J10_sale_order_line_History') AND name = N'IX_J10_sale_order_line_History_Record')
CREATE INDEX [IX_J10_sale_order_line_History_Record] ON [hist].[J10_sale_order_line_History] ([sync_source_id], [source_record_id], [is_current]);