-- =====================================================================
-- Migration: bukanmain  ->  colorindochemtrainertia (63) structure
-- Generated 2026-08-13. REGENERATED 2026-08-14 against `bukanmain2.sql` and re-verified
-- end-to-end. See "WHAT CHANGED ON 2026-08-14" below before reading anything else.
--   source : two db/bukanmain2.sql  (MariaDB 10.4, the STAGING/PRODUCTION database)
--            ⚠ NOT `bukanmain.sql`. That dump came from a replica on which `php artisan
--            migrate` had already run, so it carried 8 tables production does not have.
--            DO NOT regenerate anything from it.
--   target : the LIVE `colorindochemtrainertia` database (MySQL 8.4, DEVELOPMENT).
--            ⚠ NOT `cci_63.sql` alone: that dump was taken 2026-08-13 09:49 and is STALE --
--            it predates migrations 2026_08_13_100300 / _100400 / _100500, all of which have
--            since run on dev. Every difference in this script was re-derived from the live
--            database. The 9 dump-vs-live differences map exactly to those three migrations;
--            there is no unexplained drift.
--
-- ---------------------------------------------------------------------
-- WHAT CHANGED ON 2026-08-14, AND WHY IT MATTERED
--
-- The previous revision was built by comparing `bukanmain.sql` against `cci_63.sql`. That
-- comparison was sound for 254 of 255 table-sets but wrong about one thing, and the one thing
-- was fatal: `bukanmain.sql` had been dumped from a replica that had ALREADY been through
-- `php artisan migrate`. It therefore contained `cache`, `cache_locks`, `failed_jobs`,
-- `job_batches`, `jobs`, `migrations`, `notification` and `sessions`. The diff saw them on both
-- sides, concluded there was nothing to do, and this script created none of them.
--
-- Production has never had a migration run against it and has none of the 8. The result was
-- `Base table or view not found: ...sessions` -- recorded at the time as an operator error. It
-- was not. It was this script.
--
-- PROVEN, not assumed: `bukanmain2.sql` and `bukanmain.sql` are byte-identical across all 254
-- shared CREATE TABLE statements and all 7 views. Those 8 tables are their ONLY difference.
-- So everything the previous revision worked out about the 244 shared tables still holds, and
-- has been re-verified empirically rather than taken on trust (see below).
--
-- Changes in this revision:
--   * NEW SECTION 2b creates the 8 tables. Criterion 6: all 8 are necessary.
--   * NEW SECTION 9 seeds `migrations` with 27 rows so `php artisan migrate` afterwards is a
--     short, guarded pass instead of a replay of everything. FOUR migrations are deliberately
--     NOT seeded because each does real work this script cannot -- see section 9.
--   * SECTION 0's `ALTER DATABASE` no longer names a database.
--   * Section 2's table census corrected: the gap is 67, not 59. The 55 skipped tables were
--     re-derived from scratch; verdict unchanged, but two of the old justifications were wrong.
--
-- HOW THIS REVISION WAS VERIFIED (2026-08-14):
--   `bukanmain2.sql` was loaded into a scratch database, this entire script was run against it,
--   and the result was diffed against the live 63 database. 0 errors. The ONLY remaining
--   differences were: `vehiclestatus.ID` auto_increment (deliberate, see below), the two
--   `quotation` pagination indexes (created by artisan -- see section 9), 50 foreign keys whose
--   endpoints are on skipped tables or are the two provably-wrong PaymentTerm keys, and the 3
--   production-only legacy tables this script leaves alone. Nothing else.
--
-- 63 is DEVELOPMENT. bukanmain is STAGING and PRODUCTION, and the Laravel + Inertia app will
-- run against it. That is why this script is conservative about what it introduces and refuses
-- to remove anything.
--
-- ACCEPTANCE CRITERIA (user, 2026-08-13). bukanmain is the SOURCE OF TRUTH:
--   1. Foreign keys are the ONE exempt subject.
--   2. Everything else follows bukanmain.
--   3. Changes to bukanmain are ADDITIVE ONLY, except the data cleanup foreign keys require.
--   4. Primary keys follow bukanmain.
--   5. bukanmain has it and 63 does not  -> artisan migration adds it to 63.
--   6. 63 has it and bukanmain does not  -> into this script ONLY if necessary; otherwise 63
--                                           keeps it, recorded as deliberate.
--   7. Same thing, different shape       -> follow bukanmain; 63 moves by artisan migration.
--
-- WHAT MOVED TO THE 63 SIDE INSTEAD OF HAPPENING HERE (all are artisan migrations):
--   2026_08_13_100000_widen_remark_columns_to_text            41 remark columns, varchar -> text
--   2026_08_13_100100_restructure_country_to_int_pk_with_code `country` rebuilt on legacy shape
--   2026_08_13_100200_repoint_salesrebateinvoice_status_fks…  GH #260, wrong lookup table
--   2026_08_13_100300_add_legacy_only_columns                 the 4 columns section 3c used to DROP
--   2026_08_13_100400_widen_decimals_to_match_legacy_precisi… the 4 decimals section 3d narrowed
--   2026_08_13_100500_relax_depname_to_match_legacy           the column section 4b tightened
--   2026_08_14_100100_narrow_quotation_decimals_to_match_le…  the 3 decimals section 3d
--                                                             OVERFLOWED on production
--
-- DELIBERATE EXCLUSIONS (63 quirks treated as damage, not intent):
--   * `vehiclestatus`.`ID` keeps its AUTO_INCREMENT (63 has none). It is a fixed 3-row lookup.
--     ⚠ Strictly this is the one place the script does not satisfy criterion 5 (bukanmain has
--     it, 63 does not -> artisan migration for 63). It is the ONLY column-level difference left
--     after this script runs. Raised for a decision rather than settled silently.
--   * quotation.idx_quotation_isdeleted_id and .._tanggal_id are INVISIBLE in 63; MariaDB 10.4
--     cannot express that, so this script does not create them.
--     ⚠⚠ THIS ONLY WORKS BECAUSE SECTION 9 DOES NOT SEED
--     `2026_08_01_100000_add_quotation_list_indexes`. That migration detects MariaDB and creates
--     both indexes WITHOUT the keyword, and it self-guards on information_schema, so artisan
--     adds them safely afterwards. If someone ever "tidies" section 9 by seeding all 31
--     migrations, these two indexes are never created by anything: the paginator COUNT on the
--     Quotation list goes back to a clustered scan (measured on 10k rows: 2.6 MB instead of
--     40 KB) on every request, and nothing errors to tell you.
--   * The one `DROP INDEX` in this file (section 7, `visitplan`.`VisitPlanStatusID`) is NOT a
--     narrowing, despite appearances. bukanmain carries TWO identical 7-column composites on
--     that table (`VisitPlanStatusID` and `VisitPlanStatusID_2`); the statement re-cuts the
--     first to 1 column while `_2` keeps the composite, and section 7 adds a third. Verified on
--     the scratch run: the 7-column composite is present TWICE afterwards. Nothing is lost, so
--     criterion 3 ("additive only") is satisfied in effect.
--   * AUTO_INCREMENT counters are never copied (data-dependent).
--   * The 3 tables and 1 view bukanmain has and 63 does not are left ALONE:
--     `salesrebatedetails`, `salesrebatedetailshistory`, `salesrebatehistory`, view `vwvisitplan`.
--     `salesrebatedetails` (16 columns) is a superseded generation of `salesrebatedetail`
--     (55 columns); bukanmain carries both. Nothing here drops a table (ATURAN ABSOLUT #1).
--   * 63's view `vwijin` is not created here. The 6 shared views differ only in DEFINER.
--   * Section 9 (3 index drops) was REMOVED: not additive, and each was an exact duplicate of a
--     surviving index anyway, so keeping them costs write time only.
--
-- >>> TAKE A FULL BACKUP BEFORE RUNNING. Sections 5 and 6 modify data. <<<
-- >>> RUN audit_bukanmain_before_migrate.sql FIRST. It only reads. <<<
-- >>> THE SCRIPT IS NOT RESUMABLE. DDL implicit-commits and ADD INDEX / ADD CONSTRAINT fail on
--     a second run. A run that dies leaves a half-migrated schema whose only clean recovery is
--     that backup. Sections 5 and 6 are the exception: they are one transaction.
-- >>> RUN IT WITHOUT `--force`. THIS MATTERS MORE THAN IT LOOKS. <<<
--     Without --force the client stops at the first error and the server rolls back the open
--     transaction when the connection closes, which is what makes sections 4c/5/6 all-or-nothing.
--     WITH --force, execution continues past a failure inside that transaction and still reaches
--     the COMMIT, committing a partially applied data cleanup -- precisely the state the
--     transaction exists to prevent. Measured: a forced re-run of this whole file against an
--     already-migrated database returns rc=0 and leaves `migrations` holding 54 rows instead of
--     27. A clean run without --force stops safely at the first CREATE TABLE in section 2.
-- =====================================================================
-- The session mode is COMPUTED, not appended, and it does two opposite things on purpose.
-- Restored from @OLD_SQL_MODE at the end of the file.
--
--   + STRICT_TRANS_TABLES is FORCED ON.
--     Everything this script and the audit promise about failing loudly depends on it. Without
--     it the decimal conversions in section 3d do not abort on an out-of-range value; they CLAMP,
--     silently. Measured: decimal(20,2) -> decimal(20,10) turned 99999999999.00 into
--     9999999999.9999999999, no error, with a warning the mysql client never prints.
--     An earlier revision merely DEMANDED this of the operator and refused to run otherwise.
--     That was the wrong call -- the script can simply set it, and setting it is what makes the
--     promise true rather than aspirational.
--
--   - NO_ZERO_DATE and NO_ZERO_IN_DATE are FORCED OFF, for the WHOLE run.
--     bukanmain is a legacy database written for years under a non-strict server, so its date and
--     datetime columns hold '0000-00-00'. Under NO_ZERO_DATE, ANY ALTER that rebuilds such a
--     table re-validates those rows and fails with ERROR 1292 -- not just the two columns section
--     3b adds, but every charset and decimal conversion on every table that carries a legacy zero
--     date. Measured on a table holding one '0000-00-00' row: with NO_ZERO_DATE a plain
--     latin1->utf8mb4 MODIFY aborts; without it the same statement succeeds and the zero date is
--     preserved unchanged.
--     This is not a licence to write new zero dates -- it is what lets EXISTING ones survive a
--     table copy. 63 holds the same values (19 of 21 purchaseorder.BLDate rows), so preserving
--     them is what makes the two databases match.
--
--   + NO_AUTO_VALUE_ON_ZERO, as before.
--
-- The REPLACE order matters only in that neither name is a substring of the other; both orders
-- work. Empty list elements left behind by REPLACE are tolerated -- verified, the resulting mode
-- reads back as a clean list.
    REPLACE(REPLACE(@@SQL_MODE, 'NO_ZERO_IN_DATE', ''), 'NO_ZERO_DATE', ''),
    ',NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES'
);
-- FOREIGN_KEY_CHECKS is deliberately left ON so that any row the cleanup in sections 5-6
-- failed to catch aborts the script loudly instead of silently creating an unenforced
-- constraint.


-- ---------------------------------------------------------------------
-- PRE-FLIGHT ASSERTION - sql_mode
-- The SET above already forces the mode this script needs, so in normal operation both SELECTs
-- below simply print and the run continues. This is a belt-and-braces assertion, not a demand on
-- the operator: it catches the case where the SET did not take effect -- a server that refuses
-- STRICT_TRANS_TABLES, a proxy or connector that rewrites the session mode, or someone editing
-- the SET above without understanding what depends on it.
--
-- Both lines print unconditionally, on purpose. The effective mode belongs in the run log
-- whatever happens; "no output" is the wrong way to report the setting the whole run rests on.
--
-- If STRICT_TRANS_TABLES is somehow still absent, the else-branch subquery returns two rows,
-- which is ERROR 1242 "Subquery returns more than 1 row" -- an abort, and it happens BEFORE the
-- first mutating statement (the ALTER DATABASE in section 0). Nothing is changed. Verified both
-- ways on MySQL 8.4, and observed for real on 2026-08-13 against a MariaDB/XAMPP bukanmain whose
-- server mode was NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION -- no STRICT. The abort is
-- what sent us back to look, and it is why the SET above now forces the mode instead of hoping.
-- ---------------------------------------------------------------------
-- ⚠ ONE UNVERIFIED ASSUMPTION, AND IT IS CHEAP TO SETTLE (2026-08-14).
-- The IF() below returns a deliberately TWO-ROW subquery on its false branch, so that an absent
-- STRICT_TRANS_TABLES raises ERROR 1242 "Subquery returns more than 1 row" -- an abort before
-- the first mutating statement. Both directions were reproduced on MySQL 8.4, which
-- short-circuits IF() and never evaluates the untaken branch.
-- The history matters: the abort that fired on the real MariaDB server on 2026-08-13 was the
-- FALSE branch, back when this script only DEMANDED strict mode. Now that the SET above FORCES
-- it, the condition is always true on a real run -- so the branch that has NEVER been exercised
-- on MariaDB is the only one that will execute. If MariaDB's optimizer folds that constant
-- two-row subquery during optimization rather than short-circuiting, this aborts every time.
-- The failure is SAFE (nothing has changed yet) but would look exactly like the 2026-08-13
-- incident and waste a maintenance window.
-- BEFORE CUTOVER: paste the two SELECTs below into a MariaDB session on their own. One second.
-- If they abort, delete this assertion -- the SET above already guarantees what it checks.
SELECT @@SQL_MODE AS sql_mode_in_effect;
SELECT IF(@@SQL_MODE LIKE '%STRICT_TRANS_TABLES%',
          'sql_mode OK - proceeding',
          (SELECT 'ABORT: STRICT_TRANS_TABLES is NOT set - out-of-range values would be clamped silently'
           UNION ALL
           SELECT 'The SET at the top of this file should have set it. Find out what un-set it before re-running.')
       ) AS preflight_sql_mode;

-- ---------------------------------------------------------------------
-- SECTION 0 - Schema default charset
-- Changes no existing table. Without it, any table created on bukanmain AFTERWARDS
-- without an explicit charset inherits the old default and drifts back apart from 63 --
-- latin1 columns that 500 on emoji or CJK. See .claude/rules/column-charset.md.
-- ---------------------------------------------------------------------
-- The database is deliberately NOT NAMED here. `ALTER DATABASE` with the name omitted applies
-- to the database currently selected by the connection, so this script runs correctly whatever
-- the target is called -- `bukanmain`, `bukanmain2`, or the production name. The previous
-- revision hard-coded `bukanmain`, which was already the wrong name for the clean dump and
-- would have silently altered the WRONG database had one by that name existed on the server.
-- Verified accepted and effective on MySQL 8.4; documented identically for MariaDB 10.4
-- ("ALTER {DATABASE | SCHEMA} [db_name] ... if omitted, applies to the default database").
-- PART 0b of the audit prints DATABASE() so the run log records which one it actually was.
ALTER DATABASE DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------
-- SECTION 1 - Table storage engine (0) and table default charset (1)
-- The default charset governs columns added LATER; it does not touch existing columns.
-- The columns of these tables that actually change charset are in section 3d.
-- ---------------------------------------------------------------------
ALTER TABLE `netsuiteinvoicedetail` DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- ---------------------------------------------------------------------
-- SECTION 2 - New tables (4 of the 67 that 63 has and bukanmain lacks)
--
-- ⚠ THE COUNT USED TO SAY 59. That was the fingerprint of the wrong dump: the old
--   `bukanmain.sql` carried 8 Laravel runtime tables the real production database does not
--   have, so the gap looked like 67 - 8 = 59. Against `bukanmain2.sql` it is 67. Section 2b
--   creates those 8; this section creates 4; the remaining 55 stay out.
--
-- 63 is DEVELOPMENT; bukanmain is STAGING and PRODUCTION. Only tables with a proven
-- application code path are introduced to production (user decision 2026-08-13,
-- criterion 6 "provided they are necessary"). The other 55 stay in 63 and are recorded
-- there as deliberate; they are NOT created here. Every one was re-derived from scratch on
-- 2026-08-14 by five independent sweeps, each covering models, DB::table/join/from, raw SQL,
-- concatenated and variable table names, relations, seeders, factories, commands, jobs, mail,
-- routes, Blade and JSX. Verdict: 55 unreachable, 0 must-create. The buckets:
--   * 15 forecast tables. Unreachable because menus 470-479 and 492-499 all carry a blank
--     `LinkLaravel` -- NOT "470-499", which was wrong: 480-491 are Company Category and
--     Pengelolaan CC Web. `User::allowedMenuLinks()` filters `LinkLaravel != ''` and
--     `Menu::navTreeForRole()` prunes blank leaves, so neither the gate nor the sidebar can
--     reach them (.claude/rules/rolemenu-authz.md). ⚠ All 18 rows DO carry live `rolemenu`
--     grants; the blank link is the only thing gating them.
--   * 12 lookups and leftovers: city, province, continent, subdistrict, kodeposrex, insurance,
--     baranglistprice, linkwithother, goodidea, demo, webrouter, user_review. No
--     Province->City->Subdistrict cascade exists anywhere -- every address field is free text.
--     `insurance` is a decoy: all its code hits are the `vehicle`.`Insurance` COLUMN, which is
--     live and must keep working.
--   * 11 carry the (old)/(new)/_2/old suffixes. Every model targets the UNSUFFIXED table, which
--     bukanmain already has. ⚠ TWO exceptions to that framing, both still safe to skip but for
--     a different reason: `(new)companyprojectdetailassignment` has no unsuffixed counterpart
--     anywhere (the live table is `companyprojectdetailsassignment`, with an "s"), and
--     `invoicesalesrebatedetailold` has none either (the live analogue is the differently-worded
--     `salesrebateinvoicedetail`). Do not "restore" either under a name the app never used.
--   * 11 unreferenced islands: nscustomer, nsinvoice, nsinvoicedetail, nsprincipal,
--     nssalesincharge, userchat, usergroupchat, userprincipalgroupdivision, filetable,
--     filetablefield, filetablerows. ⚠ CORRECTION: the five `ns*` tables are NOT on the NetSuite
--     connection -- the `#[Table]` attribute has no `connection` parameter and no model sets
--     `protected $connection`, so they resolve to the DEFAULT connection, i.e. this database.
--     They are skippable because nothing reads them, NOT because they live elsewhere.
--     `netsuiteinvoicedetail` is the counter-example: a main-DB NetSuite mirror that IS live and
--     that bukanmain already has.
--   * 6 rebate/commission: salesrebateinvoicegenerate(+assignment,+status), komisisales
--     (+assignment,+detail). ⚠ Naming trap: the live module "Generate Company Rebate" uses
--     `salesrebateinvoice*`, not `salesrebateinvoicegenerate*`.
--
-- The four created here, and why each is necessary:
--   budgetandtargetachievements  CompanyController::MERGE_TABLES - counted and UPDATEd on merge
--   budgetandtargetreal          same code path
--   nsproduct                    CompanyRebateController - the company-rebates/catalog route
--   quotationitemorigin          FK parent of quotationdetails.ItemOriginID, which section 3b
--                                adds and which is in QuotationDetails::$fillable
--
-- NO 'DROP TABLE IF EXISTS' HERE, deliberately. Their absence from bukanmain is asserted from
-- `bukanmain2.sql` (2026-08-14), not checked at run time. A DROP would discard rows silently;
-- without it the CREATE fails loudly. PARTs 0b and C of the audit tell you in advance.
--
-- FOREIGN KEY clauses are stripped from these CREATEs and re-added in section 8, so creation
-- order cannot matter. The indexes that back those keys are kept here.
--
-- ⚠ THESE FOUR ARRIVE EMPTY. No rows are copied from 63 (user decision: production loads its
--   own data). Two of the four fail in DIFFERENT ways while empty, and one of them fails
--   SILENTLY -- load both before relying on anything that reads them:
--
--   `quotationitemorigin` is a LOOKUP. Until its rows exist, quotationdetails.ItemOriginID can
--     only hold NULL, because section 8 puts a RESTRICT key on it. In 63 that column is
--     populated on 394 of 534 rows, so the feature is live. Writes are REFUSED, loudly.
--
--   `nsproduct` fails QUIETLY, which is worse. CompanyRebateController::catalog() (the method
--     is `catalog()`, at CompanyRebateController.php:507 -- an earlier revision of this comment
--     named a `catalogOptions()` that does not exist) returns HTTP 200 with
--     {"principals":[],"products":[]}. Company Rebate Create then renders with two empty
--     pickers and no error anywhere. 63 holds 2,379 rows.
-- ---------------------------------------------------------------------
CREATE TABLE `budgetandtargetachievements` (
  `ID` int NOT NULL AUTO_INCREMENT,
  `IsDeleted` int NOT NULL,
  `BudgetAndTargetStatusID` int DEFAULT NULL,
  `Tanggal` datetime NOT NULL,
  `AchievedTarget` datetime NOT NULL,
  `BudgetAndTargetPeriodeID` int DEFAULT NULL,
  `UserIDInput` int DEFAULT NULL,
  `UserIDSales` int DEFAULT NULL,
  `DivisionID` int DEFAULT NULL,
  `CompanyID` int DEFAULT NULL,
  `BarangID` int DEFAULT NULL,
  `QuantityInKG` decimal(20,10) NOT NULL,
  `UnitPriceUSD` decimal(20,10) NOT NULL,
  `UnitPriceIDR` decimal(20,10) NOT NULL,
  `ValueUSD` decimal(20,10) NOT NULL,
  `ValueIDR` decimal(20,10) NOT NULL,
  `Comment` varchar(500) NOT NULL,
  PRIMARY KEY (`ID`),
  KEY `BudgetAndTargetStatusID` (`BudgetAndTargetStatusID`,`BudgetAndTargetPeriodeID`,`UserIDInput`,`UserIDSales`,`DivisionID`,`CompanyID`,`BarangID`),
  KEY `budgetandtargetachievements_BudgetAndTargetPeriodeID` (`BudgetAndTargetPeriodeID`),
  KEY `budgetandtargetachievements_UserIDInput` (`UserIDInput`),
  KEY `budgetandtargetachievements_UserIDSales` (`UserIDSales`),
  KEY `budgetandtargetachievements_DivisionID` (`DivisionID`),
  KEY `budgetandtargetachievements_CompanyID` (`CompanyID`),
  KEY `budgetandtargetachievements_BarangID` (`BarangID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `budgetandtargetreal` (
  `ID` int NOT NULL AUTO_INCREMENT,
  `IsDeleted` int NOT NULL,
  `BudgetAndTargetStatusID` int DEFAULT NULL,
  `Tanggal` datetime NOT NULL,
  `BudgetAndTargetPeriodeID` int DEFAULT NULL,
  `UserIDInput` int DEFAULT NULL,
  `UserIDSales` int DEFAULT NULL,
  `PrincipalID` int DEFAULT NULL,
  `DivisionID` int DEFAULT NULL,
  `CompanyID` int DEFAULT NULL,
  `QtBudget` decimal(20,5) NOT NULL,
  `QtTarget` decimal(20,5) NOT NULL,
  `UnitPriceUSD` decimal(20,5) NOT NULL,
  `UnitPriceIDR` decimal(20,5) NOT NULL,
  `ValueBudgetUSD` decimal(20,5) NOT NULL,
  `ValueTargetUSD` decimal(20,5) NOT NULL,
  `ValueIDR` decimal(20,5) NOT NULL,
  `Comment` varchar(500) NOT NULL,
  `ASTProductCode` varchar(200) NOT NULL,
  `ASTProductName` varchar(200) NOT NULL,
  `ASTPrincipalCode` varchar(100) NOT NULL,
  `ASTPrincipalName` varchar(100) NOT NULL,
  `QtyBudgetPM` decimal(25,2) NOT NULL,
  `QtyBudgetSM` decimal(25,2) NOT NULL,
  `QtyBudgetMM` decimal(25,2) NOT NULL,
  `QtyTargetPM` decimal(25,2) NOT NULL,
  `QtyTargetSM` decimal(25,2) NOT NULL,
  `QtyTargetMM` decimal(25,2) NOT NULL,
  `UnitPricePM` decimal(25,2) NOT NULL,
  `UnitPriceSM` decimal(25,2) NOT NULL,
  `UnitPriceMM` decimal(25,2) NOT NULL,
  `ValueBudgetUSDPM` decimal(25,2) NOT NULL,
  `ValueBudgetUSDSM` decimal(25,2) NOT NULL,
  `ValueBudgetUSDMM` decimal(25,2) NOT NULL,
  `ValueTargetUSDPM` decimal(25,2) NOT NULL,
  `ValueTargetUSDSM` decimal(25,2) NOT NULL,
  `ValueTargetUSDMM` decimal(25,2) NOT NULL,
  PRIMARY KEY (`ID`),
  KEY `BudgetAndTargetStatusID` (`BudgetAndTargetStatusID`,`BudgetAndTargetPeriodeID`,`UserIDInput`,`UserIDSales`,`DivisionID`,`CompanyID`),
  KEY `PrincipalID` (`PrincipalID`),
  KEY `budgetandtargetreal_BudgetAndTargetPeriodeID` (`BudgetAndTargetPeriodeID`),
  KEY `budgetandtargetreal_UserIDInput` (`UserIDInput`),
  KEY `budgetandtargetreal_UserIDSales` (`UserIDSales`),
  KEY `budgetandtargetreal_DivisionID` (`DivisionID`),
  KEY `budgetandtargetreal_CompanyID` (`CompanyID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `nsproduct` (
  `ID` int NOT NULL AUTO_INCREMENT,
  `isDeleted` int NOT NULL,
  `PrincipalNSCode` varchar(100) NOT NULL,
  `PrincipalNSName` varchar(200) NOT NULL,
  `ProductNSCode` varchar(100) NOT NULL,
  `ProductNSName` varchar(200) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `quotationitemorigin` (
  `ID` int NOT NULL AUTO_INCREMENT,
  `IsDeleted` int NOT NULL,
  `IsSelected` int NOT NULL,
  `ItemOriginName` varchar(255) NOT NULL,
  `Remark` varchar(255) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- ---------------------------------------------------------------------
-- SECTION 2b - The 8 tables the Laravel runtime needs   (NEW 2026-08-14)
--
-- WHY THIS SECTION EXISTS AT ALL. Every earlier revision of this script was generated against
-- `bukanmain.sql`, a dump taken 2026-08-13 03:34 from a replica on which `php artisan migrate`
-- had ALREADY been run. That replica carried these 8 tables, so the comparison saw them on both
-- sides and this script never created them. The real production database has never had a
-- migration run against it and has none of them. `bukanmain2.sql` (2026-08-14 04:18) is the
-- clean dump. Proven: the two dumps are byte-identical across all 254 shared CREATE TABLE
-- statements, and these 8 tables are their ONLY difference.
--
-- That is why production raised `Base table or view not found: ...sessions`. It was not an
-- operator mistake -- the table genuinely was not there, and this script was why.
--
-- CRITERION 6 ("63 has it and bukanmain does not -> into this script ONLY if necessary").
-- All 8 are necessary, and each for a checkable reason rather than a judgement call:
--
--   sessions       .env SESSION_DRIVER=database. No table -> nobody can log in. This is the
--                  one production actually hit.
--   cache          .env CACHE_STORE=database.
--   cache_locks    same driver; Laravel's database store takes its locks through this table.
--   jobs           .env QUEUE_CONNECTION=database.
--   job_batches    same driver.
--   failed_jobs    same driver; the worker writes here when a job exhausts its retries.
--   migrations     `php artisan migrate` cannot run without it. Section 9 seeds it.
--   notification   a REAL application table, not framework furniture: the in-app notification
--                  inbox behind the header bell (GH #322). Reached by app/Models/Notification.php,
--                  Notifier.php:106 (DB::table('notification')->insert), NotificationController
--                  .php:137, PruneNotifications.php:46/:67, and route notifications.open
--                  (routes/web.php:119).
--
-- SHAPES COME FROM THE LIVE 63 DATABASE (SHOW CREATE TABLE, 2026-08-14), not from cci_63.sql,
-- which is stale. VERIFIED EMPIRICALLY: these 8 CREATEs were run into a scratch database and
-- every resulting SHOW CREATE TABLE is byte-identical to 63's, AUTO_INCREMENT counters aside.
-- For `notification` the shape is also exactly what 2026_08_09_100000_create_notification_table
-- produces, so that migration's tableExists() guard makes the later artisan pass a clean no-op.
--
-- ⚠ `notification` IS latin1 ON PURPOSE. Do not "modernise" it to utf8mb4. Its `LinkLaravel` is
--   compared against `menu`.`LinkLaravel` (latin1) to decide whether the recipient may still open
--   the record; written as a JOIN instead of a bound whereIn, a utf8mb4 copy raises "Illegal mix
--   of collations" -- a runtime 500 on the bell, from a change that looks unrelated. The other 7
--   are utf8mb4/utf8mb4_unicode_ci, which is what Laravel's own migrations produce and what 63
--   has.
--
-- ⚠ SIX OF THESE PIN `ROW_FORMAT=DYNAMIC`, and it is not decoration. `sessions`.`id`,
--   `cache`.`key`, `cache_locks`.`key`, `job_batches`.`id`, `failed_jobs`.`uuid` and
--   `jobs`.`queue` are each varchar(255) utf8mb4 = 1020 bytes of index key, and
--   `failed_jobs_connection_queue_failed_at_index` is 2044. InnoDB allows 3072 under
--   ROW_FORMAT=DYNAMIC but only 767 under COMPACT or REDUNDANT, where every one of them fails
--   with `ERROR 1071 Specified key was too long`. MariaDB 10.4's default
--   `innodb_default_row_format` IS `dynamic` (the default since 10.2.2), so this should never
--   fire -- but `innodb_default_row_format=compact` in a my.ini is the classic
--   Laravel-on-XAMPP failure, and nothing else in this script would tell you in advance.
--   Pinning it costs nothing when the server default already is dynamic. 63's copies are
--   Dynamic too; they simply inherit it rather than spelling it out, so the only difference is
--   the DDL text, not the physical format. `migrations` and `notification` are not pinned --
--   neither has an index key anywhere near the limit.
--
-- ⚠ NO `IF NOT EXISTS`, matching section 2. PART 0b of the audit re-checks their absence against
--   the live server before you run. If one somehow exists, this CREATE fails loudly rather than
--   leaving a table of unknown shape in place -- which is exactly what went wrong the first time.
--
-- ⚠ NONE of the 8 takes part in a foreign key, in either direction, anywhere in 63 (verified
--   against information_schema.KEY_COLUMN_USAGE on the live database). So this section needs no
--   ordering relative to sections 7 and 8, and section 8 adds nothing to these tables.
--
-- ⚠ ALL 8 ARRIVE EMPTY, and here that is correct rather than a caveat: sessions, cache,
--   cache_locks, jobs, job_batches and failed_jobs are runtime scratch Laravel fills itself,
--   `notification` accrues from live events, and `migrations` is filled by section 9.
-- ---------------------------------------------------------------------
CREATE TABLE `sessions` (
  `id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `user_id` int DEFAULT NULL,
  `ip_address` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_agent` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `last_activity` int NOT NULL,
  PRIMARY KEY (`id`),
  KEY `sessions_user_id_index` (`user_id`),
  KEY `sessions_last_activity_index` (`last_activity`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `cache` (
  `key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `value` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `expiration` bigint NOT NULL,
  PRIMARY KEY (`key`),
  KEY `cache_expiration_index` (`expiration`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `cache_locks` (
  `key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `owner` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `expiration` bigint NOT NULL,
  PRIMARY KEY (`key`),
  KEY `cache_locks_expiration_index` (`expiration`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `jobs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `queue` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `attempts` smallint unsigned NOT NULL,
  `reserved_at` int unsigned DEFAULT NULL,
  `available_at` int unsigned NOT NULL,
  `created_at` int unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `jobs_queue_index` (`queue`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `job_batches` (
  `id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `total_jobs` int NOT NULL,
  `pending_jobs` int NOT NULL,
  `failed_jobs` int NOT NULL,
  `failed_job_ids` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `options` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `cancelled_at` int DEFAULT NULL,
  `created_at` int NOT NULL,
  `finished_at` int DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

-- `failed_at` carries an EXPLICIT DEFAULT on purpose. It is the first TIMESTAMP column in the
-- table, and a first TIMESTAMP declared with NEITHER a DEFAULT nor an ON UPDATE is given BOTH
-- automatically. On MariaDB 10.4, where explicit_defaults_for_timestamp is OFF by default, that
-- would silently attach ON UPDATE CURRENT_TIMESTAMP and rewrite failed_at on every UPDATE.
-- Spelling the DEFAULT out suppresses that and reproduces 63 exactly.
CREATE TABLE `failed_jobs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `uuid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `connection` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `queue` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `exception` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `failed_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `failed_jobs_uuid_unique` (`uuid`),
  KEY `failed_jobs_connection_queue_failed_at_index` (`connection`,`queue`,`failed_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `migrations` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `migration` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `batch` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `notification` (
  `ID` int NOT NULL AUTO_INCREMENT,
  `IsDeleted` int NOT NULL DEFAULT 0,
  `UserID` int NOT NULL,
  `EventKey` varchar(60) NOT NULL,
  `Module` varchar(40) NOT NULL,
  `Title` varchar(200) NOT NULL,
  `Message` varchar(500) NOT NULL,
  `LinkLaravel` varchar(200) NOT NULL,
  `RefID` int NOT NULL DEFAULT 0,
  `IsRead` int NOT NULL DEFAULT 0,
  `ReadAt` datetime NULL DEFAULT NULL,
  `Tanggal` datetime NOT NULL,
  `UserIDInput` int NOT NULL DEFAULT 0,
  PRIMARY KEY (`ID`),
  KEY `idx_notification_user_unread` (`UserID`,`IsRead`,`IsDeleted`),
  KEY `idx_notification_user_id` (`UserID`,`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

-- SECTION 3 - Column renames, additions, type changes and order
-- NOTHING IS REMOVED. Sub-section 3c, which dropped 4 columns, was deleted on 2026-08-13:
-- dropping a populated column from production is unrecoverable and no foreign key required it.
-- The letters 3a/3b/3d/3e are unchanged so existing notes still point at the right thing.
-- ---------------------------------------------------------------------
-- 3a. Renames (2). MariaDB 10.4 has no RENAME COLUMN (added in 10.5.2), so
--     CHANGE COLUMN is used. These are RENAMES, not drop+add: MySQL column names are
--     case-insensitive, so these are provably the same column and the existing values
--     (password hashes in particular) are preserved.
ALTER TABLE `users`
  CHANGE COLUMN `username` `Username` varchar(20) NOT NULL,
  CHANGE COLUMN `password` `Password` varchar(255) NOT NULL;

-- 3b. New columns (34)
ALTER TABLE `branch`
  ADD COLUMN `KodeKecamatan` varchar(200) NOT NULL AFTER `Kecamatan`,
  ADD COLUMN `Kota` varchar(200) NOT NULL AFTER `KodeKecamatan`,
  ADD COLUMN `KodeKota` varchar(200) NOT NULL AFTER `Kota`,
  ADD COLUMN `KodeProvinsi` varchar(200) NOT NULL AFTER `KodeKota`;
ALTER TABLE `company`
  ADD COLUMN `latitude` varchar(20) NOT NULL AFTER `CompanyAddress`,
  ADD COLUMN `longitude` varchar(20) NOT NULL AFTER `latitude`;
ALTER TABLE `companycp`
  ADD COLUMN `latitude` varchar(20) NOT NULL AFTER `CompanyCPKodePos`,
  ADD COLUMN `longitude` varchar(20) NOT NULL AFTER `latitude`;
ALTER TABLE `companyproject`
  ADD COLUMN `RemarkSM` varchar(255) NOT NULL AFTER `CommentProject`;
ALTER TABLE `country`
  ADD COLUMN `country_code` char(2) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL AFTER `country_name`;
ALTER TABLE `menu`
  ADD COLUMN `LinkLaravel` varchar(500) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL AFTER `Link`,
  ADD COLUMN `Icon` varchar(50) DEFAULT NULL AFTER `LinkLaravel`,
  ADD COLUMN `Path` varchar(500) NOT NULL DEFAULT '' AFTER `Icon`;
-- ⚠ ZERO DATES. `purchaseorder`.`BLDate` (date) and `users`.`OtpExpiration` (datetime) are
--   NOT NULL with no DEFAULT in 63, so on a populated table the server must invent
--   '0000-00-00' / '0000-00-00 00:00:00'. Under NO_ZERO_DATE that is ERROR 1292.
--   63 itself holds those zero values today (19 of 21 purchaseorder rows, 165 of 167 users
--   rows), so writing them here is what makes bukanmain match 63 -- the filler IS the faithful
--   end state, and only the ALTER that writes it was ever at risk.
--
--   This block used to lift NO_ZERO_DATE for just these two statements and restore it straight
--   after. That was too narrow. The same setting breaks EVERY table rebuild on a table holding a
--   legacy zero date -- each charset conversion in 3d, each decimal change, anything that copies
--   the table -- not only the two columns added here. So NO_ZERO_DATE and NO_ZERO_IN_DATE are now
--   cleared once, for the whole run, in the SET at the top of this file. Nothing to do here.
ALTER TABLE `purchaseorder`
  ADD COLUMN `PurchasePlanNo` varchar(200) NOT NULL AFTER `Tanggal`,
  ADD COLUMN `PINo` varchar(200) NOT NULL AFTER `PurchasePlanNo`,
  ADD COLUMN `SalesContract` varchar(200) NOT NULL AFTER `PINo`,
  ADD COLUMN `Invoice` varchar(200) NOT NULL AFTER `SalesContract`,
  ADD COLUMN `PrincipalOrigin` varchar(200) NOT NULL AFTER `Invoice`,
  ADD COLUMN `TermOfPayment` varchar(200) NOT NULL AFTER `PrincipalOrigin`,
  ADD COLUMN `SalesTerms` varchar(200) NOT NULL AFTER `TermOfPayment`,
  ADD COLUMN `TaxExemption` varchar(200) NOT NULL AFTER `SalesTerms`,
  ADD COLUMN `PortOfOrigin` varchar(255) NOT NULL AFTER `TaxExemption`,
  ADD COLUMN `PortOfDestination` varchar(255) NOT NULL AFTER `PortOfOrigin`,
  ADD COLUMN `ShipMethod` varchar(255) NOT NULL AFTER `PortOfDestination`,
  ADD COLUMN `ShipInLCLFCL` varchar(200) NOT NULL AFTER `ShipMethod`,
  ADD COLUMN `BLDate` date NOT NULL AFTER `ShipInLCLFCL`;
ALTER TABLE `purchaseorderhargajual`
  ADD COLUMN `HargaJualType` varchar(10) NOT NULL AFTER `UserIDInput`;
ALTER TABLE `quotationdetails`
  ADD COLUMN `ItemOriginID` int DEFAULT NULL AFTER `ProjectIDDetails`;
ALTER TABLE `sampleorderdetail`
  ADD COLUMN `IsStockReturnable` int NOT NULL DEFAULT '0' AFTER `SuratJalanDetailID`;
ALTER TABLE `samplerequestimportgoodsreceipt`
  ADD COLUMN `IsRequestList` int NOT NULL AFTER `Keterangan`;
ALTER TABLE `users`
  ADD COLUMN `PasswordResetToken` varchar(255) DEFAULT NULL AFTER `Password`,
  ADD COLUMN `PasswordResetTokenCreatedAt` datetime DEFAULT NULL AFTER `PasswordResetToken`,
  ADD COLUMN `Otp` int NOT NULL AFTER `IsHeadDept`,
  ADD COLUMN `OtpExpiration` datetime NOT NULL AFTER `Otp`;

-- 3d. Type / charset changes (21)
--     latin1 -> utf8mb4 WIDENS: every latin1 byte sequence is representable in utf8mb4, so
--     nothing is truncated. int -> decimal and int -> varchar also widen. All 24 below are
--     lossless in the bukanmain -> 63 direction.
--
--     ⚠ FOUR CONVERSIONS WERE REMOVED FROM THIS SECTION on 2026-08-13. They NARROWED
--       bukanmain and would have changed production data with no foreign key to justify it,
--       which criterion 3 forbids and criterion 7 resolves the other way round:
--         `budgetandtarget`.`UnitPriceUSD`  decimal(20,10) -> decimal(20,5)   [rounded silently]
--         `budgetandtarget`.`UnitPriceIDR`  decimal(20,10) -> decimal(20,5)   [rounded silently]
--         `budgetandtarget`.`ValueIDR`      decimal(20,10) -> decimal(20,5)   [rounded silently]
--         `packing`.`Weight`               decimal(20,10) -> decimal(10,2)   [rounded, could overflow]
--       bukanmain KEEPS decimal(20,10) on all four. 63 is widened to match instead, by
--       migration 2026_08_13_100400_widen_decimals_to_match_legacy_precision. Verified safe:
--       63 holds max 10500 in UnitPriceUSD and 222 in packing.Weight, so nothing overflows
--       the 10 integer digits decimal(20,10) allows.
--
--     Statements are grouped ONE PER TABLE. Each ALTER on an InnoDB table with a charset or
--     decimal change copies the whole table; ungrouped, netsuiteinvoicedetail was rewritten
--     11 times and budgetandtarget 3 times in this section alone.
ALTER TABLE `companyhistory`
  MODIFY COLUMN `IndustryID` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  MODIFY COLUMN `CompanyCategoryID` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
ALTER TABLE `complainassignment` MODIFY COLUMN `Comment` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL;
ALTER TABLE `complaindetails`
  MODIFY COLUMN `QuantityPacking` decimal(20,5) NOT NULL,
  MODIFY COLUMN `ComplainQuantity` decimal(20,5) NOT NULL;
ALTER TABLE `netsuiteinvoicedetail`
  MODIFY COLUMN `Quarter` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `CompanyID` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `CompanyName` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `CompanyDivision` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `SalesCustomer` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `SalesTransaction` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `ItemVendor` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `ItemBrand` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `ItemCode` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `ItemName` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `PersenProfit` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  MODIFY COLUMN `Profitability` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;
ALTER TABLE `quotation`
  MODIFY COLUMN `IndustryID` varchar(100) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL;
-- ⚠ REMOVED 2026-08-14, AFTER A REAL PRODUCTION ABORT. Three conversions used to live here:
--       quotation.USDRate          decimal(20,2) -> decimal(20,10)
--       quotationdetails.USDRate   decimal(20,2) -> decimal(20,10)
--       quotationdetails.UnitPriceIDR decimal(20,2) -> decimal(20,10)
--   The first one succeeded on production; the second statement aborted with
--       ERROR 1264 (22003) Out of range value for column 'UnitPriceIDR' at row 11061
--   THE CLASSIFICATION WAS WRONG, not the data. Section 3d's header called all 24 conversions
--   "lossless in the bukanmain -> 63 direction". For these three that is false: total precision
--   stays 20 while the scale goes 2 -> 10, so the INTEGER side narrows from 18 digits to 10 --
--   a hard ceiling of 10^10. Real production rows exceed it. STRICT_TRANS_TABLES is the only
--   reason this aborted instead of silently clamping the value, which is exactly what the top
--   of this file forces it on for.
--
--   RESOLUTION, criterion 2 ("everything must be according to bukanmain") and criterion 3
--   (additive only): production KEEPS decimal(20,2), and 63 comes to meet it. Measured on the
--   live 63 database before deciding -- of 167 quotation rows and 534 quotationdetails rows,
--   the number using MORE than 2 decimal places is ZERO in all three columns. So 63's
--   decimal(20,10) is unused precision and narrowing it is provably lossless.
--   63 moves by migration 2026_08_14_100100_narrow_quotation_decimals_to_match_legacy.
--
--   ⚠ IF YOU ALREADY RAN THE OLD SCRIPT AND IT ABORTED HERE: `quotation`.`USDRate` was already
--   converted to decimal(20,10) before the abort. Put it back with
--       ALTER TABLE `quotation` MODIFY COLUMN `USDRate` decimal(20,2) NOT NULL;
--   That is lossless -- every surviving value already fits, or the conversion would not have
--   succeeded, and none of them carries more than 2 decimal places.
ALTER TABLE `salesrebatedetail` MODIFY COLUMN `Recipient` varchar(500) NOT NULL;
ALTER TABLE `samplerequestimportgoodsreceipt` MODIFY COLUMN `QuantityReceived` decimal(20,5) NOT NULL;
ALTER TABLE `suratjalan` MODIFY COLUMN `Vendor` varchar(200) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL;

-- 3e. Column ORDER (9). Cosmetic: no value changes. The table is rewritten only so that
--     `SELECT *` and future dumps line up with 63, which is how this comparison is maintained.
--     Grouped into ONE ALTER per table: as 9 separate statements this rewrote budgetandtarget
--     9 times for an identical end state. Safe to skip entirely -- nothing else depends on it.
ALTER TABLE `budgetandtarget`
  MODIFY COLUMN `UnitPricePM` decimal(25,2) NOT NULL AFTER `QtyTargetMM`,
  MODIFY COLUMN `UnitPriceSM` decimal(25,2) NOT NULL AFTER `UnitPricePM`,
  MODIFY COLUMN `UnitPriceMM` decimal(25,2) NOT NULL AFTER `UnitPriceSM`,
  MODIFY COLUMN `ValueBudgetUSDPM` decimal(25,2) NOT NULL AFTER `UnitPriceMM`,
  MODIFY COLUMN `ValueBudgetUSDSM` decimal(25,2) NOT NULL AFTER `ValueBudgetUSDPM`,
  MODIFY COLUMN `ValueBudgetUSDMM` decimal(25,2) NOT NULL AFTER `ValueBudgetUSDSM`,
  MODIFY COLUMN `ValueTargetUSDPM` decimal(25,2) NOT NULL AFTER `ValueBudgetUSDMM`,
  MODIFY COLUMN `ValueTargetUSDSM` decimal(25,2) NOT NULL AFTER `ValueTargetUSDPM`,
  MODIFY COLUMN `ValueTargetUSDMM` decimal(25,2) NOT NULL AFTER `ValueTargetUSDSM`;

-- SECTION 4 - Relax 644 columns to NULL
-- 63 makes every foreign-key column nullable so the legacy 0-sentinel can become a real
-- NULL. A RESTRICT foreign key rejects 0, because no parent row has ID = 0. This must
-- precede sections 5-6.
--
-- ⚠ THIS COUNT HAS BEEN WRONG TWICE. Settled 2026-08-14 by two independent methods that agree:
--   644, not 645. The earlier "645" census counted a MODIFY COLUMN clause that sits inside the
--   COMMENTED-OUT sub-section 4b a few lines below -- text, not a statement. Excluding comment
--   lines, this section emits exactly 644 MODIFY COLUMN clauses across 151 ALTER statements.
--   Independently, an information_schema diff of bukanmain2 against the live 63 database finds
--   exactly 644 columns that go NOT NULL -> NULL. The two sets are IDENTICAL: nothing is relaxed
--   that does not need it, and nothing that needs it is missed. That is the check that matters;
--   the raw number is only its shadow.
--
-- Of those 644, ELEVEN receive no foreign key in section 8, so their relaxation is not paid for
-- by a constraint:
--   complaindetailsaction.DepartmentID              complaindetailsactionassignment.DepartmentID
--   complaindetailsassignment.DepartmentID          complainitemassignment.DepartmentID
--   complainitemdetailsaction.DepartmentID          complainitemdetailsactionassignment.DepartmentID
--   complainitemdetailslotassignment.DepID          quotationdetails.ProjectIDDetails
--   reference.PaymentTerm                           referencehistory.PaymentTerm
--   sampleorderdetail.ProjectIDDetails
-- The two `PaymentTerm` entries JOINED that list on 2026-08-14, when their foreign keys were
-- removed as provably wrong; the relaxation itself was left in place because 63 has both columns
-- nullable and nothing writes NULL to them. A TWELFTH unconstrained relaxation is not in this
-- section at all -- `quotation`.`IndustryID` rides along inside a section 3d type change
-- (int NOT NULL -> varchar(100) NULL). Earlier revisions said 9, then 10; the measured figure
-- today is 11 here plus 1 in section 3d.
-- ---------------------------------------------------------------------
ALTER TABLE `application`
  MODIFY COLUMN `GroupDivisionID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL;
ALTER TABLE `bank` MODIFY COLUMN `QuotationPriceDescID` int DEFAULT NULL;
ALTER TABLE `bankdivision`
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `BankID` int DEFAULT NULL;
ALTER TABLE `barang`
  MODIFY COLUMN `CategoryID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `TypeID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL;
ALTER TABLE `baranglist`
  MODIFY COLUMN `BarangListStatusID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderDetailID` int DEFAULT NULL;
ALTER TABLE `baranglists`
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL;
ALTER TABLE `barangstockmin`
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL;
ALTER TABLE `budgetandtarget`
  MODIFY COLUMN `BudgetAndTargetStatusID` int DEFAULT NULL,
  MODIFY COLUMN `BudgetAndTargetPeriodeID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL;
ALTER TABLE `budgetandtargetassignment`
  MODIFY COLUMN `BudgetAndTargetID` int DEFAULT NULL,
  MODIFY COLUMN `BudgetAndTargetStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `comissionpercentage` MODIFY COLUMN `PrincipalID` int DEFAULT NULL;
ALTER TABLE `company`
  MODIFY COLUMN `BranchID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCategoryID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL;
ALTER TABLE `companyaccessothers`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL;
ALTER TABLE `companycategory` MODIFY COLUMN `GroupDivID` int DEFAULT NULL;
ALTER TABLE `companycategorylist`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCategoryID` int DEFAULT NULL;
ALTER TABLE `companycp`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `AddressType` int DEFAULT NULL;
ALTER TABLE `companycpassignment`
  MODIFY COLUMN `UsersID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `AddressType` int DEFAULT NULL;
ALTER TABLE `companyhistory`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `BranchID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL;
ALTER TABLE `companyindustry`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL;
ALTER TABLE `companyproduct`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `CCPrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `CCBarangID` int DEFAULT NULL,
  MODIFY COLUMN `CCVolumeSatuanID` int DEFAULT NULL,
  MODIFY COLUMN `CCPriceSatuanID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorPrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorBarangID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorVolumeSatuanID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorPriceSatuanID` int DEFAULT NULL;
ALTER TABLE `companyproductapplication`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `ProductApplicationID` int DEFAULT NULL;
ALTER TABLE `companyproductassignment`
  MODIFY COLUMN `UsersID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyProductID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `CCPrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `CCBarangID` int DEFAULT NULL,
  MODIFY COLUMN `CCVolumeSatuanID` int DEFAULT NULL,
  MODIFY COLUMN `CCPriceSatuanID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorPrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorBarangID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorVolumeSatuanID` int DEFAULT NULL,
  MODIFY COLUMN `CompetitorPriceSatuanID` int DEFAULT NULL;
ALTER TABLE `companyproductcategory`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `ProductCategoryID` int DEFAULT NULL;
ALTER TABLE `companyproduction`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `VolumeSatuanID` int DEFAULT NULL;
ALTER TABLE `companyproductionassignment`
  MODIFY COLUMN `UsersID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyProductionID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `VolumeSatuanID` int DEFAULT NULL;
ALTER TABLE `companyproject`
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCP` int DEFAULT NULL,
  MODIFY COLUMN `ProjectPriority` int DEFAULT NULL;
ALTER TABLE `companyprojectassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyProjectDetailID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyProjectDetailCCID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectStatusID` int DEFAULT NULL;
ALTER TABLE `companyprojectdetailcc`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DetailID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ItemStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ItemReasonID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL,
  MODIFY COLUMN `PriceTypeID` int DEFAULT NULL,
  MODIFY COLUMN `QtTypeID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL;
ALTER TABLE `companyprojectdetailccassignment`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DetailID` int DEFAULT NULL,
  MODIFY COLUMN `DetailCCID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL,
  MODIFY COLUMN `PriceTypeID` int DEFAULT NULL,
  MODIFY COLUMN `QtTypeID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL;
ALTER TABLE `companyprojectdetailcomp`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DetailID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalIDComp` int DEFAULT NULL,
  MODIFY COLUMN `ProductIDComp` int DEFAULT NULL,
  MODIFY COLUMN `PriceTypeIDComp` int DEFAULT NULL,
  MODIFY COLUMN `QtTypeIDComp` int DEFAULT NULL,
  MODIFY COLUMN `SatuanIDComp` int DEFAULT NULL;
ALTER TABLE `companyprojectdetailcompassignment`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DetailID` int DEFAULT NULL,
  MODIFY COLUMN `DetailCompID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalIDComp` int DEFAULT NULL,
  MODIFY COLUMN `ProductIDComp` int DEFAULT NULL,
  MODIFY COLUMN `PriceTypeIDComp` int DEFAULT NULL,
  MODIFY COLUMN `QtTypeIDComp` int DEFAULT NULL,
  MODIFY COLUMN `SatuanIDComp` int DEFAULT NULL;
ALTER TABLE `companyprojectdetails`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `OpportunityGroupID` int DEFAULT NULL;
ALTER TABLE `companyprojectdetailsassignment`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DetailID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `OpportunityGroupID` int DEFAULT NULL;
ALTER TABLE `companyprojectdetailstatusassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DetailID` int DEFAULT NULL,
  MODIFY COLUMN `DetailCCID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ItemStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ItemReasonID` int DEFAULT NULL;
ALTER TABLE `companyprojectdetailstatusreason` MODIFY COLUMN `StatusID` int DEFAULT NULL;
ALTER TABLE `companyprojectheaderassignment`
  MODIFY COLUMN `CompanyProjectID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCP` int DEFAULT NULL,
  MODIFY COLUMN `ProjectPriority` int DEFAULT NULL;
ALTER TABLE `complain`
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainTypeID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainReasonID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL;
ALTER TABLE `complainassignment`
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `complaindetails`
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsStatusID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanPackingID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanComplainQuantityID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanUnitPriceUSD` int DEFAULT NULL;
ALTER TABLE `complaindetailsaction`
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `complaindetailsactionassignment`
  MODIFY COLUMN `ComplainDetailsActionID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `complaindetailsassignment`
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailsStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `complainitem`
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainTypeID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL;
ALTER TABLE `complainitemassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL;
ALTER TABLE `complainitemdetails`
  MODIFY COLUMN `ComplainItemID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `PackingMonth` int DEFAULT NULL,
  MODIFY COLUMN `PackingYear` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL;
ALTER TABLE `complainitemdetailsaction`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL;
ALTER TABLE `complainitemdetailsactionassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL;
ALTER TABLE `complainitemdetailslot`
  MODIFY COLUMN `ComplainItemID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemDetailsID` int DEFAULT NULL,
  MODIFY COLUMN `PackagingID` int DEFAULT NULL;
ALTER TABLE `complainitemdetailslotassignment`
  MODIFY COLUMN `ComplainItemID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemDetailsID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemDetailsLotID` int DEFAULT NULL,
  MODIFY COLUMN `DepID` int DEFAULT NULL,
  MODIFY COLUMN `PackagingID` int DEFAULT NULL;
ALTER TABLE `complaintosupplier`
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainTypeID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainItemTypeID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL,
  MODIFY COLUMN `PackingMonth` int DEFAULT NULL,
  MODIFY COLUMN `PackingYear` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL;
ALTER TABLE `complaintosupplierassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL;
ALTER TABLE `complaintosupplierdetailsaction`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartementID` int DEFAULT NULL;
ALTER TABLE `complaintosupplierdetailsactionassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ComplainID` int DEFAULT NULL,
  MODIFY COLUMN `ComplainStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL;
ALTER TABLE `division` MODIFY COLUMN `GroupDivisionID` int DEFAULT NULL;
ALTER TABLE `documentgroupdivision`
  MODIFY COLUMN `DocID` int DEFAULT NULL,
  MODIFY COLUMN `GroupDivID` int DEFAULT NULL;
ALTER TABLE `documentupload`
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `DocumentCategoryID` int DEFAULT NULL;
ALTER TABLE `documentuploadinternal` MODIFY COLUMN `DocumentCategoryID` int DEFAULT NULL;
ALTER TABLE `izin`
  MODIFY COLUMN `IzinTypeID` int DEFAULT NULL,
  MODIFY COLUMN `IzinTypeStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `IzinStatusID` int DEFAULT NULL;
ALTER TABLE `izinassignment`
  MODIFY COLUMN `IzinID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `IzinStatusID` int DEFAULT NULL;
ALTER TABLE `izintypestatus` MODIFY COLUMN `IzinTypeID` int DEFAULT NULL;
ALTER TABLE `labworkrequest`
  MODIFY COLUMN `LabWorkRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDProjectInitiator` int DEFAULT NULL,
  MODIFY COLUMN `LabWorkRequestFeedbackStatusID` int DEFAULT NULL;
ALTER TABLE `labworkrequestassignment`
  MODIFY COLUMN `LabWorkRequestID` int DEFAULT NULL,
  MODIFY COLUMN `LabWorkRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `labworkrequestdetails`
  MODIFY COLUMN `LabWorkRequestDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectIDComp` int DEFAULT NULL,
  MODIFY COLUMN `LabWorkRequestID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `TypeID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanIDVolume` int DEFAULT NULL,
  MODIFY COLUMN `SatuanIDUnitPrice` int DEFAULT NULL;
ALTER TABLE `labworkrequestdetailsassignment`
  MODIFY COLUMN `LabWorkRequestID` int DEFAULT NULL,
  MODIFY COLUMN `LabWorkRequestDetailID` int DEFAULT NULL,
  MODIFY COLUMN `LabWorkRequestDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `labworkrequestlink` MODIFY COLUMN `LabWorkRequestID` int DEFAULT NULL;
ALTER TABLE `lembur`
  MODIFY COLUMN `LemburTypeID` int DEFAULT NULL,
  MODIFY COLUMN `LemburStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL;
ALTER TABLE `lemburassignment`
  MODIFY COLUMN `LemburID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `LemburStatusID` int DEFAULT NULL;
ALTER TABLE `menu` MODIFY COLUMN `ParentID` int DEFAULT NULL;
ALTER TABLE `news` MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `onleave`
  MODIFY COLUMN `OnLeaveStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `UserPengganti1` int DEFAULT NULL,
  MODIFY COLUMN `UserPengganti2` int DEFAULT NULL,
  MODIFY COLUMN `OnLeaveLimitID` int DEFAULT NULL;
ALTER TABLE `onleaveadditional`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `OnLeaveLimitID` int DEFAULT NULL;
ALTER TABLE `onleaveadditionalassignment`
  MODIFY COLUMN `OnLeaveAdditionalID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `onleaveassignment`
  MODIFY COLUMN `OnLeaveID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `OnLeaveStatusID` int DEFAULT NULL;
ALTER TABLE `packing` MODIFY COLUMN `SatuanID` int DEFAULT NULL;
ALTER TABLE `potentialsales`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL;
ALTER TABLE `potentialsaleshistory`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `PotentialSalesID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL;
ALTER TABLE `principalcp`
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `AddressType` int DEFAULT NULL;
ALTER TABLE `principalcpassignment`
  MODIFY COLUMN `UsersID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalCPID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `AddressType` int DEFAULT NULL;
ALTER TABLE `principalfaq` MODIFY COLUMN `PrincipalID` int DEFAULT NULL;
ALTER TABLE `principalfaqhistory`
  MODIFY COLUMN `PrincipalFAQID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL;
ALTER TABLE `printeditemfulfillment` MODIFY COLUMN `UserIDInput` int DEFAULT NULL;
ALTER TABLE `product`
  MODIFY COLUMN `ClassID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `PackingID` int DEFAULT NULL;
ALTER TABLE `productapplication`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL;
ALTER TABLE `productcategory`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `CategoryID` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL;
ALTER TABLE `proposedcreditceiling`
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPaymentTermID` int DEFAULT NULL,
  MODIFY COLUMN `CCStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `JustificationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPaymentTermApprovedID` int DEFAULT NULL;
ALTER TABLE `proposedcreditceilinghistory`
  MODIFY COLUMN `ProposedCCID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPaymentTermID` int DEFAULT NULL,
  MODIFY COLUMN `CCStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `JustificationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPaymentTermApprovedID` int DEFAULT NULL;
ALTER TABLE `purchaseorder`
  MODIFY COLUMN `PurchaseOrderStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL;
ALTER TABLE `purchaseorderdetails`
  MODIFY COLUMN `PurchaseOrderID` int DEFAULT NULL,
  MODIFY COLUMN `PurchaseOrderDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `PackingID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanOrderQtyID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL;
ALTER TABLE `purchaseorderdetailsassignment`
  MODIFY COLUMN `PurchaseOrderID` int DEFAULT NULL,
  MODIFY COLUMN `PurchaseOrderDetailID` int DEFAULT NULL,
  MODIFY COLUMN `PurchaseOrderStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `purchaseorderhargajual` MODIFY COLUMN `UserIDInput` int DEFAULT NULL;
ALTER TABLE `quotation`
  MODIFY COLUMN `QuotationStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ReferenceQuotationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationSubjectID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationTypeID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationTitleID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `DeliveryAddressID` int DEFAULT NULL,
  MODIFY COLUMN `InvoiceAddressID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPriceDescID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationSalesTermID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPaymentTermID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationDeliveryTimeID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationValidityID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationStockAvailibilityID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationFeedbackStatusID` int DEFAULT NULL;
ALTER TABLE `quotationassignment`
  MODIFY COLUMN `QuotationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `quotationdetails`
  MODIFY COLUMN `QuotationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectIDDetails` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationPackID` int DEFAULT NULL,
  MODIFY COLUMN `PackingID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanOrderQty` int DEFAULT NULL;
ALTER TABLE `quotationdetailsassignment`
  MODIFY COLUMN `QuotationID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationDetailID` int DEFAULT NULL,
  MODIFY COLUMN `QuotationDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `quotationlink` MODIFY COLUMN `QuotationID` int DEFAULT NULL;
ALTER TABLE `reference`
  MODIFY COLUMN `PaymentTerm` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL;
ALTER TABLE `referencehistory`
  MODIFY COLUMN `ReferenceID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `PaymentTerm` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL;
ALTER TABLE `relabelhistory` MODIFY COLUMN `UserIDInput` int DEFAULT NULL;
ALTER TABLE `rolegadget`
  MODIFY COLUMN `RoleID` int DEFAULT NULL,
  MODIFY COLUMN `GadgetID` int DEFAULT NULL;
ALTER TABLE `rolemenu`
  MODIFY COLUMN `RoleID` int DEFAULT NULL,
  MODIFY COLUMN `MenuID` int DEFAULT NULL;
ALTER TABLE `salesrebate`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateStatusID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `CCPaymentTerm` int DEFAULT NULL,
  MODIFY COLUMN `ReferenceRebateID` int DEFAULT NULL;
ALTER TABLE `salesrebateassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateID` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateStatusID` int DEFAULT NULL;
ALTER TABLE `salesrebatedetail`
  MODIFY COLUMN `SalesRebateID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL;
ALTER TABLE `salesrebateinvoice`
  MODIFY COLUMN `SalesRebateID` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateInvoiceStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserInput` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL;
ALTER TABLE `salesrebateinvoiceassignment`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateInvoiceID` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateInvoiceStatusID` int DEFAULT NULL;
ALTER TABLE `salesrebateinvoicedetail`
  MODIFY COLUMN `SalesRebateInvoiceDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateInvoiceID` int DEFAULT NULL,
  MODIFY COLUMN `SalesRebateID` int DEFAULT NULL,
  MODIFY COLUMN `PaymentCPID` int DEFAULT NULL;
ALTER TABLE `salesrebateinvoicepaymentdetail` MODIFY COLUMN `SalesRebateInvoiceDetailID` int DEFAULT NULL;
ALTER TABLE `sampleorder`
  MODIFY COLUMN `SampleOrderStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ReferenceSOID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `DeliveryID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `LocationID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `IndustryID` int DEFAULT NULL,
  MODIFY COLUMN `PriorityID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderFeedbackStatusID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderByID` int DEFAULT NULL;
ALTER TABLE `sampleorderassignment`
  MODIFY COLUMN `SampleOrderID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `sampleorderdetail`
  MODIFY COLUMN `SampleOrderID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectIDDetails` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `BarangListID` int DEFAULT NULL,
  MODIFY COLUMN `BarangListIDRequest` int DEFAULT NULL,
  MODIFY COLUMN `SuratJalanDetailID` int DEFAULT NULL;
ALTER TABLE `sampleorderdetailassignment`
  MODIFY COLUMN `SampleOrderID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderDetailID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `sampleorderlink` MODIFY COLUMN `SampleOrderID` int DEFAULT NULL;
ALTER TABLE `samplerequestimport`
  MODIFY COLUMN `SampleRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `ReferenceSRID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `DeliveryID` int DEFAULT NULL,
  MODIFY COLUMN `UrgencyID` int DEFAULT NULL,
  MODIFY COLUMN `RequestFromID` int DEFAULT NULL;
ALTER TABLE `samplerequestimportassignment`
  MODIFY COLUMN `SampleRequestImportID` int DEFAULT NULL,
  MODIFY COLUMN `SampleRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `samplerequestimportdetail`
  MODIFY COLUMN `SampleRequestImportID` int DEFAULT NULL,
  MODIFY COLUMN `SampleRequestDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  MODIFY COLUMN `ReqCompanyID` int DEFAULT NULL,
  MODIFY COLUMN `GoodReceiptDetailID` int DEFAULT NULL,
  MODIFY COLUMN `BaranglistID` int DEFAULT NULL;
ALTER TABLE `samplerequestimportdetailassignment`
  MODIFY COLUMN `SampleRequestImportID` int DEFAULT NULL,
  MODIFY COLUMN `SampleRequestDetailID` int DEFAULT NULL,
  MODIFY COLUMN `SampleRequestDetailStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `samplerequestimportgoodsreceipt`
  MODIFY COLUMN `SampleRequestImportID` int DEFAULT NULL,
  MODIFY COLUMN `SampleRequestImportDetailID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  MODIFY COLUMN `BarangListsID` int DEFAULT NULL;
ALTER TABLE `specialreference` MODIFY COLUMN `CompanyID` int DEFAULT NULL;
ALTER TABLE `specialreferencehistory`
  MODIFY COLUMN `SpecialReferenceID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL;
ALTER TABLE `stockopname`
  MODIFY COLUMN `StockOpnameBy` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `WarehouseID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL,
  MODIFY COLUMN `PackagingID` int DEFAULT NULL,
  MODIFY COLUMN `UOMID` int DEFAULT NULL;
ALTER TABLE `stockopname_product`
  MODIFY COLUMN `UOMID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL;
ALTER TABLE `stockopnamehistory`
  MODIFY COLUMN `StockOpnameID` int DEFAULT NULL,
  MODIFY COLUMN `StockOpnameStatusID` int DEFAULT NULL,
  MODIFY COLUMN `StockOpnameBy` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `WarehouseID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `ProductID` int DEFAULT NULL,
  MODIFY COLUMN `PackagingID` int DEFAULT NULL,
  MODIFY COLUMN `UOMID` int DEFAULT NULL;
ALTER TABLE `successstory`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `GroupDivisionID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL;
ALTER TABLE `successstoryassignment`
  MODIFY COLUMN `SuccessStoryID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `suratjalan`
  MODIFY COLUMN `SampleOrderID` int DEFAULT NULL,
  MODIFY COLUMN `DeliveryID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `LocationID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDsales` int DEFAULT NULL,
  MODIFY COLUMN `UserIDCreatorSJ` int DEFAULT NULL;
ALTER TABLE `suratjalandetails`
  MODIFY COLUMN `SuratJalanID` int DEFAULT NULL,
  MODIFY COLUMN `SampleOrderID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `SatuanID` int DEFAULT NULL,
  MODIFY COLUMN `ApplicationID` int DEFAULT NULL,
  MODIFY COLUMN `BarangListID` int DEFAULT NULL;
ALTER TABLE `userbusinesstravelbranch`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `BranchID` int DEFAULT NULL;
ALTER TABLE `userdetails`
  MODIFY COLUMN `BranchID` int DEFAULT NULL,
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL;
ALTER TABLE `userdivision`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL;
ALTER TABLE `usereducation`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `EducationID` int DEFAULT NULL;
ALTER TABLE `userjob` MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `userlabgroupdivision`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `GroupDivisionID` int DEFAULT NULL;
ALTER TABLE `userprincipal`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL;
ALTER TABLE `users`
  MODIFY COLUMN `DepartmentID` int DEFAULT NULL,
  MODIFY COLUMN `RoleID` int DEFAULT NULL,
  MODIFY COLUMN `MaritalStatusID` int DEFAULT NULL,
  MODIFY COLUMN `BranchID` int DEFAULT NULL,
  MODIFY COLUMN `HeadID` int DEFAULT NULL;
ALTER TABLE `usersperiode` MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `userwarehouse`
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `WarehouseID` int DEFAULT NULL;
ALTER TABLE `vehicle`
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDOwner` int DEFAULT NULL,
  MODIFY COLUMN `VehicleTypeID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleBrandID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleBrandTypeID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleColorID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleFuelTypeID` int DEFAULT NULL;
ALTER TABLE `vehicleassignment`
  MODIFY COLUMN `VehicleID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDOwnerBefore` int DEFAULT NULL,
  MODIFY COLUMN `VehicleTypeIDBefore` int DEFAULT NULL,
  MODIFY COLUMN `VehicleBrandIDBefore` int DEFAULT NULL,
  MODIFY COLUMN `VehicleBrandTypeIDBefore` int DEFAULT NULL,
  MODIFY COLUMN `VehicleColorIDBefore` int DEFAULT NULL,
  MODIFY COLUMN `VehicleFuelTypeIDBefore` int DEFAULT NULL,
  MODIFY COLUMN `UserIDOwnerAfter` int DEFAULT NULL,
  MODIFY COLUMN `VehicleTypeIDAfter` int DEFAULT NULL,
  MODIFY COLUMN `VehicleBrandIDAfter` int DEFAULT NULL,
  MODIFY COLUMN `VehicleBrandTypeIDAfter` int DEFAULT NULL,
  MODIFY COLUMN `VehicleColorIDAfter` int DEFAULT NULL,
  MODIFY COLUMN `VehicleFuelTypeIDAfter` int DEFAULT NULL;
ALTER TABLE `vehiclebrandtype` MODIFY COLUMN `VehicleBrandID` int DEFAULT NULL;
ALTER TABLE `vehicleservicerequest`
  MODIFY COLUMN `VehicleServiceRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `VehicleID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDOwner` int DEFAULT NULL;
ALTER TABLE `vehicleservicerequestassignment`
  MODIFY COLUMN `VehicleServiceRequestID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleServiceRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `vehicleservicerequestdetails`
  MODIFY COLUMN `VehicleServiceRequestID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleServiceTypeID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleServiceRequestDetailStatus` int DEFAULT NULL;
ALTER TABLE `vehicleservicerequestdetailsassigntment`
  MODIFY COLUMN `VehicleServiceRequestID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleServiceRequestDetailID` int DEFAULT NULL,
  MODIFY COLUMN `VehicleServiceRequestStatusID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL;
ALTER TABLE `visitplan`
  MODIFY COLUMN `VisitPlanStatusID` int DEFAULT NULL,
  MODIFY COLUMN `DivisionID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDInput` int DEFAULT NULL,
  MODIFY COLUMN `UserIDSales` int DEFAULT NULL,
  MODIFY COLUMN `CompanyID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDVisitWith` int DEFAULT NULL,
  MODIFY COLUMN `VisitingPrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `VisitPrincipalCPID` int DEFAULT NULL;
ALTER TABLE `visitplanassignment`
  MODIFY COLUMN `VisitPlanID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `VisitPlanStatusID` int DEFAULT NULL;
ALTER TABLE `visitplancompanycpdetail`
  MODIFY COLUMN `VisitPlanID` int DEFAULT NULL,
  MODIFY COLUMN `CompanyCPID` int DEFAULT NULL;
ALTER TABLE `visitplandetail`
  MODIFY COLUMN `VisitPlanID` int DEFAULT NULL,
  MODIFY COLUMN `ActionID` int DEFAULT NULL,
  MODIFY COLUMN `ProjectID` int DEFAULT NULL,
  MODIFY COLUMN `PrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `BarangID` int DEFAULT NULL,
  MODIFY COLUMN `VisitActionStatusID` int DEFAULT NULL;
ALTER TABLE `visitplandetailassignment`
  MODIFY COLUMN `VisitPlanID` int DEFAULT NULL,
  MODIFY COLUMN `VisitPlanDetailID` int DEFAULT NULL,
  MODIFY COLUMN `UserID` int DEFAULT NULL,
  MODIFY COLUMN `VisitPlanStatusID` int DEFAULT NULL,
  MODIFY COLUMN `VisitActionStatusID` int DEFAULT NULL;
ALTER TABLE `visitplanfrienddetail`
  MODIFY COLUMN `VisitPlanID` int DEFAULT NULL,
  MODIFY COLUMN `UserIDVisitWith` int DEFAULT NULL;
ALTER TABLE `visitplanlink` MODIFY COLUMN `VisitPlanID` int DEFAULT NULL;
ALTER TABLE `visitplanprincipalvisitdetail`
  MODIFY COLUMN `VisitPlanID` int DEFAULT NULL,
  MODIFY COLUMN `VisitingPrincipalID` int DEFAULT NULL,
  MODIFY COLUMN `VisitingPrincipalCPID` int DEFAULT NULL;
ALTER TABLE `warehouse` MODIFY COLUMN `ParentID` int DEFAULT NULL;

-- 4b. REMOVED on 2026-08-13. It read:
--        ALTER TABLE `complainitemdetailslotassignment` MODIFY COLUMN `DepName` varchar(200) NOT NULL;
--      and was documented -- here, in the DIFF and in the audit -- as converting existing NULLs
--      to '' "with a warning rather than an error". THAT IS NOT WHAT HAPPENS. Under
--      STRICT_TRANS_TABLES, which this script deliberately keeps on and which MariaDB 10.4 also
--      enables by default, it is ERROR 1138 "Invalid use of NULL value" and the script ABORTS --
--      reproduced on MySQL 8.4. It is also the only non-FK statement that rewrote bukanmain data,
--      which criteria 1 and 3 both forbid. 63 relaxes the column to nullable instead, by
--      migration 2026_08_13_100500_relax_depname_to_match_legacy.

-- ---------------------------------------------------------------------
-- SECTIONS 5 AND 6 RUN AS ONE TRANSACTION.
-- Both contain nothing but InnoDB UPDATEs -- 1,273 of them (1 in 4c + 636 in 5 + 636 in 6),
-- no DDL -- so no implicit commit can
-- split them. Without this, a lock wait, a deadlock against the legacy app, or an operator
-- Ctrl-C part way through leaves production with some foreign-key columns cleaned and the rest
-- not, no rollback, and nothing in the output saying where it stopped. The script is not
-- resumable, so that state is only recoverable from the backup.
-- ⚠ CORRECTED 2026-08-14. The previous revision set only `lock_wait_timeout` here and RESTORED
-- it immediately after the COMMIT, which applied the guard to the sections that do not need it
-- and removed it before the ones that do:
--   * `lock_wait_timeout` bounds METADATA-lock waits. Sections 4c/5/6 are 1,273 InnoDB UPDATEs,
--     whose contention with the live legacy app is ROW-lock contention -- governed by
--     `innodb_lock_wait_timeout` (default 50s), which was never set.
--   * Sections 7 and 8 are the 1,296 ALTERs that actually take metadata locks, and they ran
--     OUTSIDE the guard at MariaDB 10.4's default `lock_wait_timeout` of 86400 seconds. One
--     ALTER stuck behind a long-running app query would stall the whole run with no timeout,
--     and every query arriving afterwards queues behind that ALTER.
-- Both are now set here and both stay set until the end of the file.
-- ---------------------------------------------------------------------
SET SESSION lock_wait_timeout = 60;
SET SESSION innodb_lock_wait_timeout = 60;
START TRANSACTION;

-- ---------------------------------------------------------------------
-- SECTION 4c - ONE-OFF DATA REPAIR: quotationdetails.QuotationPackID
--
-- 863 rows hold a QuotationPackID that `quotationpack` does not define. Without this repair,
-- section 6 would null every one of them and the information would be gone for good.
--
-- WHAT THEY ACTUALLY ARE. The values run 24-122; `quotationpack` stops at 23. All 863 resolve
-- against `packing` (ids 1-131), NONE of the 863 has a PackingID of its own (it is 0 in every
-- case), and -- the part that settles it -- `QuantityPacking` matches the leading number of the
-- corresponding `packing`.`PackingName` row for row:
--
--     QuotationPackID  QuantityPacking   packing.PackingName
--                  46            30.00   30 kg/pail
--                  56            25.00   25 kg/pail
--                  83            10.00   10 kg/pail
--                  91            20.00   20 kg/pail
--                  37            25.00   25 kg/box
--                  62             1.00   1 unit
--
-- Random ids into a 131-row table do not correlate with a quantity column. A legacy screen wrote
-- the PACKING id into the QUOTATIONPACK column. Same shape as the colliding legacy conventions
-- documented for `<detail>.ProjectID` in .claude/rules/company-project-links.md.
--
-- WHAT THIS DOES. Moves the value to the column it belongs in and leaves the 0-sentinel behind,
-- which section 5 then turns into NULL. Net effect on the schema: both foreign keys apply
-- cleanly. Net effect on the app: an improvement. `QuotationController::reportPackName()` reads
--     if ((int) $r->QuotationPackID === 0) $name = $r->PackingName;
-- so today these rows print a bare quantity with no unit -- the pack name resolves through
-- neither table. After this they print "25 kg/box" again.
--
-- The FK direction is NOT changed: `QuotationPackID` -> `quotationpack` is correct and is what
-- `QuotationDetails::quotationPack()` and five controller joins use. The data was wrong, not the
-- key. 63 needs no equivalent repair -- it has zero orphans on this column.
--
-- GUARDED THREE WAYS, so it can only touch the rows described above: the value must fail to
-- resolve in `quotationpack`, must resolve in `packing`, and the row must have no PackingID
-- already. Re-running finds nothing. It is inside the transaction with sections 5 and 6, so a
-- later failure rolls it back with them.
-- ---------------------------------------------------------------------
UPDATE `quotationdetails` d
  JOIN `packing` p ON p.`ID` = d.`QuotationPackID`
  LEFT JOIN `quotationpack` qp ON qp.`ID` = d.`QuotationPackID`
SET d.`PackingID` = d.`QuotationPackID`,
    d.`QuotationPackID` = 0
WHERE d.`QuotationPackID` IS NOT NULL
  AND d.`QuotationPackID` <> 0
  AND qp.`ID` IS NULL
  AND (d.`PackingID` = 0 OR d.`PackingID` IS NULL);

-- SECTION 5 - Normalise 0-sentinels to NULL (636 foreign-key columns)
-- The legacy schema used 0 to mean "not set". A RESTRICT foreign key rejects 0 because no
-- parent row has ID 0, so every 0 becomes NULL -- which means the same thing.
-- This is a DATA change and is not reversible from this script.
-- ---------------------------------------------------------------------
UPDATE `application` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `application` SET `GroupDivisionID` = NULL WHERE `GroupDivisionID` = 0;
UPDATE `bank` SET `QuotationPriceDescID` = NULL WHERE `QuotationPriceDescID` = 0;
UPDATE `bankdivision` SET `BankID` = NULL WHERE `BankID` = 0;
UPDATE `bankdivision` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `barang` SET `CategoryID` = NULL WHERE `CategoryID` = 0;
UPDATE `barang` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `barang` SET `SatuanID` = NULL WHERE `SatuanID` = 0;
UPDATE `barang` SET `TypeID` = NULL WHERE `TypeID` = 0;
UPDATE `baranglist` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `baranglist` SET `BarangListStatusID` = NULL WHERE `BarangListStatusID` = 0;
UPDATE `baranglist` SET `SampleOrderDetailID` = NULL WHERE `SampleOrderDetailID` = 0;
UPDATE `baranglist` SET `SatuanID` = NULL WHERE `SatuanID` = 0;
UPDATE `baranglists` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `baranglists` SET `SatuanID` = NULL WHERE `SatuanID` = 0;
UPDATE `barangstockmin` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `barangstockmin` SET `SatuanID` = NULL WHERE `SatuanID` = 0;
UPDATE `budgetandtarget` SET `BudgetAndTargetPeriodeID` = NULL WHERE `BudgetAndTargetPeriodeID` = 0;
UPDATE `budgetandtarget` SET `BudgetAndTargetStatusID` = NULL WHERE `BudgetAndTargetStatusID` = 0;
UPDATE `budgetandtarget` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `budgetandtarget` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `budgetandtarget` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `budgetandtarget` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `budgetandtarget` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `budgetandtargetassignment` SET `BudgetAndTargetID` = NULL WHERE `BudgetAndTargetID` = 0;
UPDATE `budgetandtargetassignment` SET `BudgetAndTargetStatusID` = NULL WHERE `BudgetAndTargetStatusID` = 0;
UPDATE `budgetandtargetassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `comissionpercentage` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `company` SET `BranchID` = NULL WHERE `BranchID` = 0;
UPDATE `company` SET `CompanyCategoryID` = NULL WHERE `CompanyCategoryID` = 0;
UPDATE `company` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `company` SET `IndustryID` = NULL WHERE `IndustryID` = 0;
UPDATE `company` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `companyaccessothers` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companyaccessothers` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `companycategory` SET `GroupDivID` = NULL WHERE `GroupDivID` = 0;
UPDATE `companycategorylist` SET `CompanyCategoryID` = NULL WHERE `CompanyCategoryID` = 0;
UPDATE `companycategorylist` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companycp` SET `AddressType` = NULL WHERE `AddressType` = 0;
UPDATE `companycp` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companycpassignment` SET `AddressType` = NULL WHERE `AddressType` = 0;
UPDATE `companycpassignment` SET `CompanyCPID` = NULL WHERE `CompanyCPID` = 0;
UPDATE `companycpassignment` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companycpassignment` SET `UsersID` = NULL WHERE `UsersID` = 0;
UPDATE `companyhistory` SET `BranchID` = NULL WHERE `BranchID` = 0;
UPDATE `companyhistory` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companyhistory` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `companyhistory` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `companyhistory` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `companyindustry` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companyindustry` SET `IndustryID` = NULL WHERE `IndustryID` = 0;
UPDATE `companyproduct` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `companyproduct` SET `CCBarangID` = NULL WHERE `CCBarangID` = 0;
UPDATE `companyproduct` SET `CCPriceSatuanID` = NULL WHERE `CCPriceSatuanID` = 0;
UPDATE `companyproduct` SET `CCPrincipalID` = NULL WHERE `CCPrincipalID` = 0;
UPDATE `companyproduct` SET `CCVolumeSatuanID` = NULL WHERE `CCVolumeSatuanID` = 0;
UPDATE `companyproduct` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companyproduct` SET `CompetitorBarangID` = NULL WHERE `CompetitorBarangID` = 0;
UPDATE `companyproduct` SET `CompetitorPriceSatuanID` = NULL WHERE `CompetitorPriceSatuanID` = 0;
UPDATE `companyproduct` SET `CompetitorPrincipalID` = NULL WHERE `CompetitorPrincipalID` = 0;
UPDATE `companyproduct` SET `CompetitorVolumeSatuanID` = NULL WHERE `CompetitorVolumeSatuanID` = 0;
UPDATE `companyproduct` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `companyproductapplication` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companyproductapplication` SET `ProductApplicationID` = NULL WHERE `ProductApplicationID` = 0;
UPDATE `companyproductassignment` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `companyproductassignment` SET `CCBarangID` = NULL WHERE `CCBarangID` = 0;
UPDATE `companyproductassignment` SET `CCPriceSatuanID` = NULL WHERE `CCPriceSatuanID` = 0;
UPDATE `companyproductassignment` SET `CCPrincipalID` = NULL WHERE `CCPrincipalID` = 0;
UPDATE `companyproductassignment` SET `CCVolumeSatuanID` = NULL WHERE `CCVolumeSatuanID` = 0;
UPDATE `companyproductassignment` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companyproductassignment` SET `CompanyProductID` = NULL WHERE `CompanyProductID` = 0;
UPDATE `companyproductassignment` SET `CompetitorBarangID` = NULL WHERE `CompetitorBarangID` = 0;
UPDATE `companyproductassignment` SET `CompetitorPriceSatuanID` = NULL WHERE `CompetitorPriceSatuanID` = 0;
UPDATE `companyproductassignment` SET `CompetitorPrincipalID` = NULL WHERE `CompetitorPrincipalID` = 0;
UPDATE `companyproductassignment` SET `CompetitorVolumeSatuanID` = NULL WHERE `CompetitorVolumeSatuanID` = 0;
UPDATE `companyproductassignment` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `companyproductassignment` SET `UsersID` = NULL WHERE `UsersID` = 0;
UPDATE `companyproductcategory` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companyproductcategory` SET `ProductCategoryID` = NULL WHERE `ProductCategoryID` = 0;
UPDATE `companyproduction` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `companyproduction` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companyproduction` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `companyproduction` SET `VolumeSatuanID` = NULL WHERE `VolumeSatuanID` = 0;
UPDATE `companyproductionassignment` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `companyproductionassignment` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companyproductionassignment` SET `CompanyProductionID` = NULL WHERE `CompanyProductionID` = 0;
UPDATE `companyproductionassignment` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `companyproductionassignment` SET `UsersID` = NULL WHERE `UsersID` = 0;
UPDATE `companyproductionassignment` SET `VolumeSatuanID` = NULL WHERE `VolumeSatuanID` = 0;
UPDATE `companyproject` SET `CompanyCP` = NULL WHERE `CompanyCP` = 0;
UPDATE `companyproject` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companyproject` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `companyproject` SET `IndustryID` = NULL WHERE `IndustryID` = 0;
UPDATE `companyproject` SET `ProjectID` = NULL WHERE `ProjectID` = 0;
UPDATE `companyproject` SET `ProjectPriority` = NULL WHERE `ProjectPriority` = 0;
UPDATE `companyproject` SET `ProjectStatusID` = NULL WHERE `ProjectStatusID` = 0;
UPDATE `companyproject` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `companyproject` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `companyprojectassignment` SET `CompanyProjectDetailCCID` = NULL WHERE `CompanyProjectDetailCCID` = 0;
UPDATE `companyprojectassignment` SET `CompanyProjectDetailID` = NULL WHERE `CompanyProjectDetailID` = 0;
UPDATE `companyprojectassignment` SET `CompanyProjectID` = NULL WHERE `CompanyProjectID` = 0;
UPDATE `companyprojectassignment` SET `ProjectStatusID` = NULL WHERE `ProjectStatusID` = 0;
UPDATE `companyprojectassignment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `companyprojectdetailcc` SET `CompanyProjectID` = NULL WHERE `CompanyProjectID` = 0;
UPDATE `companyprojectdetailcc` SET `DetailID` = NULL WHERE `DetailID` = 0;
UPDATE `companyprojectdetailcc` SET `ItemReasonID` = NULL WHERE `ItemReasonID` = 0;
UPDATE `companyprojectdetailcc` SET `ItemStatusID` = NULL WHERE `ItemStatusID` = 0;
UPDATE `companyprojectdetailcc` SET `PriceTypeID` = NULL WHERE `PriceTypeID` = 0;
UPDATE `companyprojectdetailcc` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `companyprojectdetailcc` SET `ProductID` = NULL WHERE `ProductID` = 0;
UPDATE `companyprojectdetailcc` SET `ProjectStatusID` = NULL WHERE `ProjectStatusID` = 0;
UPDATE `companyprojectdetailcc` SET `QtTypeID` = NULL WHERE `QtTypeID` = 0;
UPDATE `companyprojectdetailcc` SET `SatuanID` = NULL WHERE `SatuanID` = 0;
UPDATE `companyprojectdetailccassignment` SET `CompanyProjectID` = NULL WHERE `CompanyProjectID` = 0;
UPDATE `companyprojectdetailccassignment` SET `DetailCCID` = NULL WHERE `DetailCCID` = 0;
UPDATE `companyprojectdetailccassignment` SET `DetailID` = NULL WHERE `DetailID` = 0;
UPDATE `companyprojectdetailccassignment` SET `PriceTypeID` = NULL WHERE `PriceTypeID` = 0;
UPDATE `companyprojectdetailccassignment` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `companyprojectdetailccassignment` SET `ProductID` = NULL WHERE `ProductID` = 0;
UPDATE `companyprojectdetailccassignment` SET `QtTypeID` = NULL WHERE `QtTypeID` = 0;
UPDATE `companyprojectdetailccassignment` SET `SatuanID` = NULL WHERE `SatuanID` = 0;
UPDATE `companyprojectdetailccassignment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `companyprojectdetailcomp` SET `CompanyProjectID` = NULL WHERE `CompanyProjectID` = 0;
UPDATE `companyprojectdetailcomp` SET `DetailID` = NULL WHERE `DetailID` = 0;
UPDATE `companyprojectdetailcomp` SET `PriceTypeIDComp` = NULL WHERE `PriceTypeIDComp` = 0;
UPDATE `companyprojectdetailcomp` SET `PrincipalIDComp` = NULL WHERE `PrincipalIDComp` = 0;
UPDATE `companyprojectdetailcomp` SET `ProductIDComp` = NULL WHERE `ProductIDComp` = 0;
UPDATE `companyprojectdetailcomp` SET `QtTypeIDComp` = NULL WHERE `QtTypeIDComp` = 0;
UPDATE `companyprojectdetailcomp` SET `SatuanIDComp` = NULL WHERE `SatuanIDComp` = 0;
UPDATE `companyprojectdetailcompassignment` SET `CompanyProjectID` = NULL WHERE `CompanyProjectID` = 0;
UPDATE `companyprojectdetailcompassignment` SET `DetailCompID` = NULL WHERE `DetailCompID` = 0;
UPDATE `companyprojectdetailcompassignment` SET `DetailID` = NULL WHERE `DetailID` = 0;
UPDATE `companyprojectdetailcompassignment` SET `PriceTypeIDComp` = NULL WHERE `PriceTypeIDComp` = 0;
UPDATE `companyprojectdetailcompassignment` SET `PrincipalIDComp` = NULL WHERE `PrincipalIDComp` = 0;
UPDATE `companyprojectdetailcompassignment` SET `ProductIDComp` = NULL WHERE `ProductIDComp` = 0;
UPDATE `companyprojectdetailcompassignment` SET `QtTypeIDComp` = NULL WHERE `QtTypeIDComp` = 0;
UPDATE `companyprojectdetailcompassignment` SET `SatuanIDComp` = NULL WHERE `SatuanIDComp` = 0;
UPDATE `companyprojectdetailcompassignment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `companyprojectdetails` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `companyprojectdetails` SET `CompanyProjectID` = NULL WHERE `CompanyProjectID` = 0;
UPDATE `companyprojectdetails` SET `OpportunityGroupID` = NULL WHERE `OpportunityGroupID` = 0;
UPDATE `companyprojectdetails` SET `ProjectStatusID` = NULL WHERE `ProjectStatusID` = 0;
UPDATE `companyprojectdetailsassignment` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `companyprojectdetailsassignment` SET `CompanyProjectID` = NULL WHERE `CompanyProjectID` = 0;
UPDATE `companyprojectdetailsassignment` SET `DetailID` = NULL WHERE `DetailID` = 0;
UPDATE `companyprojectdetailsassignment` SET `OpportunityGroupID` = NULL WHERE `OpportunityGroupID` = 0;
UPDATE `companyprojectdetailsassignment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `companyprojectdetailstatusassignment` SET `CompanyProjectID` = NULL WHERE `CompanyProjectID` = 0;
UPDATE `companyprojectdetailstatusassignment` SET `DetailCCID` = NULL WHERE `DetailCCID` = 0;
UPDATE `companyprojectdetailstatusassignment` SET `DetailID` = NULL WHERE `DetailID` = 0;
UPDATE `companyprojectdetailstatusassignment` SET `ItemReasonID` = NULL WHERE `ItemReasonID` = 0;
UPDATE `companyprojectdetailstatusassignment` SET `ItemStatusID` = NULL WHERE `ItemStatusID` = 0;
UPDATE `companyprojectdetailstatusassignment` SET `ProjectStatusID` = NULL WHERE `ProjectStatusID` = 0;
UPDATE `companyprojectdetailstatusassignment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `companyprojectdetailstatusreason` SET `StatusID` = NULL WHERE `StatusID` = 0;
UPDATE `companyprojectheaderassignment` SET `CompanyCP` = NULL WHERE `CompanyCP` = 0;
UPDATE `companyprojectheaderassignment` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `companyprojectheaderassignment` SET `CompanyProjectID` = NULL WHERE `CompanyProjectID` = 0;
UPDATE `companyprojectheaderassignment` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `companyprojectheaderassignment` SET `IndustryID` = NULL WHERE `IndustryID` = 0;
UPDATE `companyprojectheaderassignment` SET `ProjectID` = NULL WHERE `ProjectID` = 0;
UPDATE `companyprojectheaderassignment` SET `ProjectPriority` = NULL WHERE `ProjectPriority` = 0;
UPDATE `companyprojectheaderassignment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `companyprojectheaderassignment` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `complain` SET `CompanyCPID` = NULL WHERE `CompanyCPID` = 0;
UPDATE `complain` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `complain` SET `ComplainReasonID` = NULL WHERE `ComplainReasonID` = 0;
UPDATE `complain` SET `ComplainStatusID` = NULL WHERE `ComplainStatusID` = 0;
UPDATE `complain` SET `ComplainTypeID` = NULL WHERE `ComplainTypeID` = 0;
UPDATE `complain` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `complain` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `complain` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `complainassignment` SET `ComplainID` = NULL WHERE `ComplainID` = 0;
UPDATE `complainassignment` SET `ComplainStatusID` = NULL WHERE `ComplainStatusID` = 0;
UPDATE `complainassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `complaindetails` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `complaindetails` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `complaindetails` SET `ComplainDetailsStatusID` = NULL WHERE `ComplainDetailsStatusID` = 0;
UPDATE `complaindetails` SET `ComplainID` = NULL WHERE `ComplainID` = 0;
UPDATE `complaindetails` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `complaindetails` SET `SatuanComplainQuantityID` = NULL WHERE `SatuanComplainQuantityID` = 0;
UPDATE `complaindetails` SET `SatuanPackingID` = NULL WHERE `SatuanPackingID` = 0;
UPDATE `complaindetails` SET `SatuanUnitPriceUSD` = NULL WHERE `SatuanUnitPriceUSD` = 0;
UPDATE `complaindetailsaction` SET `ComplainDetailsID` = NULL WHERE `ComplainDetailsID` = 0;
UPDATE `complaindetailsaction` SET `ComplainDetailsStatusID` = NULL WHERE `ComplainDetailsStatusID` = 0;
UPDATE `complaindetailsaction` SET `ComplainID` = NULL WHERE `ComplainID` = 0;
UPDATE `complaindetailsaction` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `complaindetailsactionassignment` SET `ComplainDetailsActionID` = NULL WHERE `ComplainDetailsActionID` = 0;
UPDATE `complaindetailsactionassignment` SET `ComplainDetailsID` = NULL WHERE `ComplainDetailsID` = 0;
UPDATE `complaindetailsactionassignment` SET `ComplainDetailsStatusID` = NULL WHERE `ComplainDetailsStatusID` = 0;
UPDATE `complaindetailsactionassignment` SET `ComplainID` = NULL WHERE `ComplainID` = 0;
UPDATE `complaindetailsactionassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `complaindetailsassignment` SET `ComplainDetailsID` = NULL WHERE `ComplainDetailsID` = 0;
UPDATE `complaindetailsassignment` SET `ComplainDetailsStatusID` = NULL WHERE `ComplainDetailsStatusID` = 0;
UPDATE `complaindetailsassignment` SET `ComplainID` = NULL WHERE `ComplainID` = 0;
UPDATE `complaindetailsassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `complainitem` SET `ComplainStatusID` = NULL WHERE `ComplainStatusID` = 0;
UPDATE `complainitem` SET `ComplainTypeID` = NULL WHERE `ComplainTypeID` = 0;
UPDATE `complainitem` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `complainitem` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `complainitemassignment` SET `ComplainItemID` = NULL WHERE `ComplainItemID` = 0;
UPDATE `complainitemassignment` SET `ComplainItemStatusID` = NULL WHERE `ComplainItemStatusID` = 0;
UPDATE `complainitemassignment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `complainitemdetails` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `complainitemdetails` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `complainitemdetails` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `complainitemdetails` SET `ComplainDetailStatusID` = NULL WHERE `ComplainDetailStatusID` = 0;
UPDATE `complainitemdetails` SET `ComplainItemID` = NULL WHERE `ComplainItemID` = 0;
UPDATE `complainitemdetails` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `complainitemdetails` SET `IndustryID` = NULL WHERE `IndustryID` = 0;
UPDATE `complainitemdetails` SET `PackingMonth` = NULL WHERE `PackingMonth` = 0;
UPDATE `complainitemdetails` SET `PackingYear` = NULL WHERE `PackingYear` = 0;
UPDATE `complainitemdetailsaction` SET `ComplainID` = NULL WHERE `ComplainID` = 0;
UPDATE `complainitemdetailsaction` SET `ComplainStatusID` = NULL WHERE `ComplainStatusID` = 0;
UPDATE `complainitemdetailsaction` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `complainitemdetailsactionassignment` SET `ComplainItemID` = NULL WHERE `ComplainItemID` = 0;
UPDATE `complainitemdetailsactionassignment` SET `ComplainItemStatusID` = NULL WHERE `ComplainItemStatusID` = 0;
UPDATE `complainitemdetailsactionassignment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `complainitemdetailslot` SET `ComplainItemDetailsID` = NULL WHERE `ComplainItemDetailsID` = 0;
UPDATE `complainitemdetailslot` SET `ComplainItemID` = NULL WHERE `ComplainItemID` = 0;
UPDATE `complainitemdetailslot` SET `PackagingID` = NULL WHERE `PackagingID` = 0;
UPDATE `complainitemdetailslotassignment` SET `ComplainItemDetailsID` = NULL WHERE `ComplainItemDetailsID` = 0;
UPDATE `complainitemdetailslotassignment` SET `ComplainItemDetailsLotID` = NULL WHERE `ComplainItemDetailsLotID` = 0;
UPDATE `complainitemdetailslotassignment` SET `ComplainItemID` = NULL WHERE `ComplainItemID` = 0;
UPDATE `complainitemdetailslotassignment` SET `PackagingID` = NULL WHERE `PackagingID` = 0;
UPDATE `complaintosupplier` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `complaintosupplier` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `complaintosupplier` SET `ComplainItemTypeID` = NULL WHERE `ComplainItemTypeID` = 0;
UPDATE `complaintosupplier` SET `ComplainStatusID` = NULL WHERE `ComplainStatusID` = 0;
UPDATE `complaintosupplier` SET `ComplainTypeID` = NULL WHERE `ComplainTypeID` = 0;
UPDATE `complaintosupplier` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `complaintosupplier` SET `IndustryID` = NULL WHERE `IndustryID` = 0;
UPDATE `complaintosupplier` SET `PackingMonth` = NULL WHERE `PackingMonth` = 0;
UPDATE `complaintosupplier` SET `PackingYear` = NULL WHERE `PackingYear` = 0;
UPDATE `complaintosupplier` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `complaintosupplier` SET `ProductID` = NULL WHERE `ProductID` = 0;
UPDATE `complaintosupplier` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `complaintosupplier` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `complaintosupplierassignment` SET `ComplainID` = NULL WHERE `ComplainID` = 0;
UPDATE `complaintosupplierassignment` SET `ComplainStatusID` = NULL WHERE `ComplainStatusID` = 0;
UPDATE `complaintosupplierassignment` SET `DepartmentID` = NULL WHERE `DepartmentID` = 0;
UPDATE `complaintosupplierassignment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `complaintosupplierdetailsaction` SET `ComplainID` = NULL WHERE `ComplainID` = 0;
UPDATE `complaintosupplierdetailsaction` SET `ComplainStatusID` = NULL WHERE `ComplainStatusID` = 0;
UPDATE `complaintosupplierdetailsaction` SET `DepartementID` = NULL WHERE `DepartementID` = 0;
UPDATE `complaintosupplierdetailsaction` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `complaintosupplierdetailsactionassignment` SET `ComplainID` = NULL WHERE `ComplainID` = 0;
UPDATE `complaintosupplierdetailsactionassignment` SET `ComplainStatusID` = NULL WHERE `ComplainStatusID` = 0;
UPDATE `complaintosupplierdetailsactionassignment` SET `DepartmentID` = NULL WHERE `DepartmentID` = 0;
UPDATE `complaintosupplierdetailsactionassignment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `division` SET `GroupDivisionID` = NULL WHERE `GroupDivisionID` = 0;
UPDATE `documentgroupdivision` SET `DocID` = NULL WHERE `DocID` = 0;
UPDATE `documentgroupdivision` SET `GroupDivID` = NULL WHERE `GroupDivID` = 0;
UPDATE `documentupload` SET `DocumentCategoryID` = NULL WHERE `DocumentCategoryID` = 0;
UPDATE `documentupload` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `documentuploadinternal` SET `DocumentCategoryID` = NULL WHERE `DocumentCategoryID` = 0;
UPDATE `izin` SET `IzinStatusID` = NULL WHERE `IzinStatusID` = 0;
UPDATE `izin` SET `IzinTypeID` = NULL WHERE `IzinTypeID` = 0;
UPDATE `izin` SET `IzinTypeStatusID` = NULL WHERE `IzinTypeStatusID` = 0;
UPDATE `izin` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `izin` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `izinassignment` SET `IzinID` = NULL WHERE `IzinID` = 0;
UPDATE `izinassignment` SET `IzinStatusID` = NULL WHERE `IzinStatusID` = 0;
UPDATE `izinassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `izintypestatus` SET `IzinTypeID` = NULL WHERE `IzinTypeID` = 0;
UPDATE `labworkrequest` SET `CompanyCPID` = NULL WHERE `CompanyCPID` = 0;
UPDATE `labworkrequest` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `labworkrequest` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `labworkrequest` SET `IndustryID` = NULL WHERE `IndustryID` = 0;
UPDATE `labworkrequest` SET `LabWorkRequestFeedbackStatusID` = NULL WHERE `LabWorkRequestFeedbackStatusID` = 0;
UPDATE `labworkrequest` SET `LabWorkRequestStatusID` = NULL WHERE `LabWorkRequestStatusID` = 0;
UPDATE `labworkrequest` SET `ProjectID` = NULL WHERE `ProjectID` = 0;
UPDATE `labworkrequest` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `labworkrequest` SET `UserIDProjectInitiator` = NULL WHERE `UserIDProjectInitiator` = 0;
UPDATE `labworkrequest` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `labworkrequestassignment` SET `LabWorkRequestID` = NULL WHERE `LabWorkRequestID` = 0;
UPDATE `labworkrequestassignment` SET `LabWorkRequestStatusID` = NULL WHERE `LabWorkRequestStatusID` = 0;
UPDATE `labworkrequestassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `labworkrequestdetails` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `labworkrequestdetails` SET `LabWorkRequestDetailStatusID` = NULL WHERE `LabWorkRequestDetailStatusID` = 0;
UPDATE `labworkrequestdetails` SET `LabWorkRequestID` = NULL WHERE `LabWorkRequestID` = 0;
UPDATE `labworkrequestdetails` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `labworkrequestdetails` SET `ProjectID` = NULL WHERE `ProjectID` = 0;
UPDATE `labworkrequestdetails` SET `ProjectIDComp` = NULL WHERE `ProjectIDComp` = 0;
UPDATE `labworkrequestdetails` SET `SatuanIDUnitPrice` = NULL WHERE `SatuanIDUnitPrice` = 0;
UPDATE `labworkrequestdetails` SET `SatuanIDVolume` = NULL WHERE `SatuanIDVolume` = 0;
UPDATE `labworkrequestdetails` SET `TypeID` = NULL WHERE `TypeID` = 0;
UPDATE `labworkrequestdetailsassignment` SET `LabWorkRequestDetailID` = NULL WHERE `LabWorkRequestDetailID` = 0;
UPDATE `labworkrequestdetailsassignment` SET `LabWorkRequestDetailStatusID` = NULL WHERE `LabWorkRequestDetailStatusID` = 0;
UPDATE `labworkrequestdetailsassignment` SET `LabWorkRequestID` = NULL WHERE `LabWorkRequestID` = 0;
UPDATE `labworkrequestdetailsassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `labworkrequestlink` SET `LabWorkRequestID` = NULL WHERE `LabWorkRequestID` = 0;
UPDATE `lembur` SET `LemburStatusID` = NULL WHERE `LemburStatusID` = 0;
UPDATE `lembur` SET `LemburTypeID` = NULL WHERE `LemburTypeID` = 0;
UPDATE `lembur` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `lembur` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `lemburassignment` SET `LemburID` = NULL WHERE `LemburID` = 0;
UPDATE `lemburassignment` SET `LemburStatusID` = NULL WHERE `LemburStatusID` = 0;
UPDATE `lemburassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `menu` SET `ParentID` = NULL WHERE `ParentID` = 0;
UPDATE `news` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `onleave` SET `OnLeaveLimitID` = NULL WHERE `OnLeaveLimitID` = 0;
UPDATE `onleave` SET `OnLeaveStatusID` = NULL WHERE `OnLeaveStatusID` = 0;
UPDATE `onleave` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `onleave` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `onleave` SET `UserPengganti1` = NULL WHERE `UserPengganti1` = 0;
UPDATE `onleave` SET `UserPengganti2` = NULL WHERE `UserPengganti2` = 0;
UPDATE `onleaveadditional` SET `OnLeaveLimitID` = NULL WHERE `OnLeaveLimitID` = 0;
UPDATE `onleaveadditional` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `onleaveadditional` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `onleaveadditionalassignment` SET `OnLeaveAdditionalID` = NULL WHERE `OnLeaveAdditionalID` = 0;
UPDATE `onleaveadditionalassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `onleaveassignment` SET `OnLeaveID` = NULL WHERE `OnLeaveID` = 0;
UPDATE `onleaveassignment` SET `OnLeaveStatusID` = NULL WHERE `OnLeaveStatusID` = 0;
UPDATE `onleaveassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `packing` SET `SatuanID` = NULL WHERE `SatuanID` = 0;
UPDATE `potentialsales` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `potentialsales` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `potentialsales` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `potentialsaleshistory` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `potentialsaleshistory` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `potentialsaleshistory` SET `PotentialSalesID` = NULL WHERE `PotentialSalesID` = 0;
UPDATE `potentialsaleshistory` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `potentialsaleshistory` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `principalcp` SET `AddressType` = NULL WHERE `AddressType` = 0;
UPDATE `principalcp` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `principalcpassignment` SET `AddressType` = NULL WHERE `AddressType` = 0;
UPDATE `principalcpassignment` SET `PrincipalCPID` = NULL WHERE `PrincipalCPID` = 0;
UPDATE `principalcpassignment` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `principalcpassignment` SET `UsersID` = NULL WHERE `UsersID` = 0;
UPDATE `principalfaq` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `principalfaqhistory` SET `PrincipalFAQID` = NULL WHERE `PrincipalFAQID` = 0;
UPDATE `principalfaqhistory` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `printeditemfulfillment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `product` SET `ClassID` = NULL WHERE `ClassID` = 0;
UPDATE `product` SET `PackingID` = NULL WHERE `PackingID` = 0;
UPDATE `product` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `productapplication` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `productapplication` SET `ProductID` = NULL WHERE `ProductID` = 0;
UPDATE `productapplication` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `productcategory` SET `CategoryID` = NULL WHERE `CategoryID` = 0;
UPDATE `productcategory` SET `ProductID` = NULL WHERE `ProductID` = 0;
UPDATE `productcategory` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `proposedcreditceiling` SET `CCStatusID` = NULL WHERE `CCStatusID` = 0;
UPDATE `proposedcreditceiling` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `proposedcreditceiling` SET `JustificationID` = NULL WHERE `JustificationID` = 0;
UPDATE `proposedcreditceiling` SET `QuotationPaymentTermApprovedID` = NULL WHERE `QuotationPaymentTermApprovedID` = 0;
UPDATE `proposedcreditceiling` SET `QuotationPaymentTermID` = NULL WHERE `QuotationPaymentTermID` = 0;
UPDATE `proposedcreditceiling` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `proposedcreditceilinghistory` SET `CCStatusID` = NULL WHERE `CCStatusID` = 0;
UPDATE `proposedcreditceilinghistory` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `proposedcreditceilinghistory` SET `JustificationID` = NULL WHERE `JustificationID` = 0;
UPDATE `proposedcreditceilinghistory` SET `ProposedCCID` = NULL WHERE `ProposedCCID` = 0;
UPDATE `proposedcreditceilinghistory` SET `QuotationPaymentTermApprovedID` = NULL WHERE `QuotationPaymentTermApprovedID` = 0;
UPDATE `proposedcreditceilinghistory` SET `QuotationPaymentTermID` = NULL WHERE `QuotationPaymentTermID` = 0;
UPDATE `proposedcreditceilinghistory` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `purchaseorder` SET `PurchaseOrderStatusID` = NULL WHERE `PurchaseOrderStatusID` = 0;
UPDATE `purchaseorder` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `purchaseorderassignment` SET `PurchaseOrderID` = NULL WHERE `PurchaseOrderID` = 0;
UPDATE `purchaseorderassignment` SET `PurchaseOrderStatusID` = NULL WHERE `PurchaseOrderStatusID` = 0;
UPDATE `purchaseorderassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `purchaseorderdetails` SET `PackingID` = NULL WHERE `PackingID` = 0;
UPDATE `purchaseorderdetails` SET `PurchaseOrderDetailStatusID` = NULL WHERE `PurchaseOrderDetailStatusID` = 0;
UPDATE `purchaseorderdetails` SET `PurchaseOrderID` = NULL WHERE `PurchaseOrderID` = 0;
UPDATE `purchaseorderdetails` SET `SatuanID` = NULL WHERE `SatuanID` = 0;
UPDATE `purchaseorderdetails` SET `SatuanOrderQtyID` = NULL WHERE `SatuanOrderQtyID` = 0;
UPDATE `purchaseorderdetailsassignment` SET `PurchaseOrderDetailID` = NULL WHERE `PurchaseOrderDetailID` = 0;
UPDATE `purchaseorderdetailsassignment` SET `PurchaseOrderID` = NULL WHERE `PurchaseOrderID` = 0;
UPDATE `purchaseorderdetailsassignment` SET `PurchaseOrderStatusID` = NULL WHERE `PurchaseOrderStatusID` = 0;
UPDATE `purchaseorderdetailsassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `purchaseorderhargajual` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `quotation` SET `CompanyCPID` = NULL WHERE `CompanyCPID` = 0;
UPDATE `quotation` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `quotation` SET `DeliveryAddressID` = NULL WHERE `DeliveryAddressID` = 0;
UPDATE `quotation` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `quotation` SET `InvoiceAddressID` = NULL WHERE `InvoiceAddressID` = 0;
UPDATE `quotation` SET `QuotationDeliveryTimeID` = NULL WHERE `QuotationDeliveryTimeID` = 0;
UPDATE `quotation` SET `QuotationFeedbackStatusID` = NULL WHERE `QuotationFeedbackStatusID` = 0;
UPDATE `quotation` SET `QuotationPaymentTermID` = NULL WHERE `QuotationPaymentTermID` = 0;
UPDATE `quotation` SET `QuotationPriceDescID` = NULL WHERE `QuotationPriceDescID` = 0;
UPDATE `quotation` SET `QuotationSalesTermID` = NULL WHERE `QuotationSalesTermID` = 0;
UPDATE `quotation` SET `QuotationStatusID` = NULL WHERE `QuotationStatusID` = 0;
UPDATE `quotation` SET `QuotationStockAvailibilityID` = NULL WHERE `QuotationStockAvailibilityID` = 0;
UPDATE `quotation` SET `QuotationSubjectID` = NULL WHERE `QuotationSubjectID` = 0;
UPDATE `quotation` SET `QuotationTitleID` = NULL WHERE `QuotationTitleID` = 0;
UPDATE `quotation` SET `QuotationTypeID` = NULL WHERE `QuotationTypeID` = 0;
UPDATE `quotation` SET `QuotationValidityID` = NULL WHERE `QuotationValidityID` = 0;
UPDATE `quotation` SET `ReferenceQuotationID` = NULL WHERE `ReferenceQuotationID` = 0;
UPDATE `quotation` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `quotation` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `quotationassignment` SET `QuotationID` = NULL WHERE `QuotationID` = 0;
UPDATE `quotationassignment` SET `QuotationStatusID` = NULL WHERE `QuotationStatusID` = 0;
UPDATE `quotationassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `quotationdetails` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `quotationdetails` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `quotationdetails` SET `PackingID` = NULL WHERE `PackingID` = 0;
UPDATE `quotationdetails` SET `ProjectID` = NULL WHERE `ProjectID` = 0;
UPDATE `quotationdetails` SET `QuotationDetailStatusID` = NULL WHERE `QuotationDetailStatusID` = 0;
UPDATE `quotationdetails` SET `QuotationID` = NULL WHERE `QuotationID` = 0;
UPDATE `quotationdetails` SET `QuotationPackID` = NULL WHERE `QuotationPackID` = 0;
UPDATE `quotationdetails` SET `SatuanID` = NULL WHERE `SatuanID` = 0;
UPDATE `quotationdetails` SET `SatuanOrderQty` = NULL WHERE `SatuanOrderQty` = 0;
UPDATE `quotationdetailsassignment` SET `QuotationDetailID` = NULL WHERE `QuotationDetailID` = 0;
UPDATE `quotationdetailsassignment` SET `QuotationDetailStatusID` = NULL WHERE `QuotationDetailStatusID` = 0;
UPDATE `quotationdetailsassignment` SET `QuotationID` = NULL WHERE `QuotationID` = 0;
UPDATE `quotationdetailsassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `quotationlink` SET `QuotationID` = NULL WHERE `QuotationID` = 0;
UPDATE `reference` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `referencehistory` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `referencehistory` SET `ReferenceID` = NULL WHERE `ReferenceID` = 0;
UPDATE `referencehistory` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `relabelhistory` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `rolegadget` SET `GadgetID` = NULL WHERE `GadgetID` = 0;
UPDATE `rolegadget` SET `RoleID` = NULL WHERE `RoleID` = 0;
UPDATE `rolemenu` SET `MenuID` = NULL WHERE `MenuID` = 0;
UPDATE `rolemenu` SET `RoleID` = NULL WHERE `RoleID` = 0;
UPDATE `salesrebate` SET `CCPaymentTerm` = NULL WHERE `CCPaymentTerm` = 0;
UPDATE `salesrebate` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `salesrebate` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `salesrebate` SET `IndustryID` = NULL WHERE `IndustryID` = 0;
UPDATE `salesrebate` SET `ReferenceRebateID` = NULL WHERE `ReferenceRebateID` = 0;
UPDATE `salesrebate` SET `SalesRebateStatusID` = NULL WHERE `SalesRebateStatusID` = 0;
UPDATE `salesrebate` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `salesrebate` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `salesrebateassignment` SET `SalesRebateID` = NULL WHERE `SalesRebateID` = 0;
UPDATE `salesrebateassignment` SET `SalesRebateStatusID` = NULL WHERE `SalesRebateStatusID` = 0;
UPDATE `salesrebateassignment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `salesrebatedetail` SET `CompanyCPID` = NULL WHERE `CompanyCPID` = 0;
UPDATE `salesrebatedetail` SET `SalesRebateID` = NULL WHERE `SalesRebateID` = 0;
UPDATE `salesrebateinvoice` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `salesrebateinvoice` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `salesrebateinvoice` SET `IndustryID` = NULL WHERE `IndustryID` = 0;
UPDATE `salesrebateinvoice` SET `SalesRebateID` = NULL WHERE `SalesRebateID` = 0;
UPDATE `salesrebateinvoice` SET `SalesRebateInvoiceStatusID` = NULL WHERE `SalesRebateInvoiceStatusID` = 0;
UPDATE `salesrebateinvoice` SET `UserInput` = NULL WHERE `UserInput` = 0;
UPDATE `salesrebateinvoiceassignment` SET `SalesRebateInvoiceID` = NULL WHERE `SalesRebateInvoiceID` = 0;
UPDATE `salesrebateinvoiceassignment` SET `SalesRebateInvoiceStatusID` = NULL WHERE `SalesRebateInvoiceStatusID` = 0;
UPDATE `salesrebateinvoiceassignment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `salesrebateinvoicedetail` SET `PaymentCPID` = NULL WHERE `PaymentCPID` = 0;
UPDATE `salesrebateinvoicedetail` SET `SalesRebateID` = NULL WHERE `SalesRebateID` = 0;
UPDATE `salesrebateinvoicedetail` SET `SalesRebateInvoiceDetailStatusID` = NULL WHERE `SalesRebateInvoiceDetailStatusID` = 0;
UPDATE `salesrebateinvoicedetail` SET `SalesRebateInvoiceID` = NULL WHERE `SalesRebateInvoiceID` = 0;
UPDATE `salesrebateinvoicepaymentdetail` SET `SalesRebateInvoiceDetailID` = NULL WHERE `SalesRebateInvoiceDetailID` = 0;
UPDATE `sampleorder` SET `CompanyCPID` = NULL WHERE `CompanyCPID` = 0;
UPDATE `sampleorder` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `sampleorder` SET `DeliveryID` = NULL WHERE `DeliveryID` = 0;
UPDATE `sampleorder` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `sampleorder` SET `IndustryID` = NULL WHERE `IndustryID` = 0;
UPDATE `sampleorder` SET `LocationID` = NULL WHERE `LocationID` = 0;
UPDATE `sampleorder` SET `PriorityID` = NULL WHERE `PriorityID` = 0;
UPDATE `sampleorder` SET `ProjectID` = NULL WHERE `ProjectID` = 0;
UPDATE `sampleorder` SET `ReferenceSOID` = NULL WHERE `ReferenceSOID` = 0;
UPDATE `sampleorder` SET `SampleOrderByID` = NULL WHERE `SampleOrderByID` = 0;
UPDATE `sampleorder` SET `SampleOrderFeedbackStatusID` = NULL WHERE `SampleOrderFeedbackStatusID` = 0;
UPDATE `sampleorder` SET `SampleOrderStatusID` = NULL WHERE `SampleOrderStatusID` = 0;
UPDATE `sampleorder` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `sampleorder` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `sampleorderassignment` SET `SampleOrderID` = NULL WHERE `SampleOrderID` = 0;
UPDATE `sampleorderassignment` SET `SampleOrderStatusID` = NULL WHERE `SampleOrderStatusID` = 0;
UPDATE `sampleorderassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `sampleorderdetail` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `sampleorderdetail` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `sampleorderdetail` SET `BarangListID` = NULL WHERE `BarangListID` = 0;
UPDATE `sampleorderdetail` SET `BarangListIDRequest` = NULL WHERE `BarangListIDRequest` = 0;
UPDATE `sampleorderdetail` SET `ProjectID` = NULL WHERE `ProjectID` = 0;
UPDATE `sampleorderdetail` SET `SampleOrderDetailStatusID` = NULL WHERE `SampleOrderDetailStatusID` = 0;
UPDATE `sampleorderdetail` SET `SampleOrderID` = NULL WHERE `SampleOrderID` = 0;
UPDATE `sampleorderdetail` SET `SatuanID` = NULL WHERE `SatuanID` = 0;
UPDATE `sampleorderdetail` SET `SuratJalanDetailID` = NULL WHERE `SuratJalanDetailID` = 0;
UPDATE `sampleorderdetailassignment` SET `SampleOrderDetailID` = NULL WHERE `SampleOrderDetailID` = 0;
UPDATE `sampleorderdetailassignment` SET `SampleOrderDetailStatusID` = NULL WHERE `SampleOrderDetailStatusID` = 0;
UPDATE `sampleorderdetailassignment` SET `SampleOrderID` = NULL WHERE `SampleOrderID` = 0;
UPDATE `sampleorderdetailassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `sampleorderlink` SET `SampleOrderID` = NULL WHERE `SampleOrderID` = 0;
UPDATE `samplerequestimport` SET `DeliveryID` = NULL WHERE `DeliveryID` = 0;
UPDATE `samplerequestimport` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `samplerequestimport` SET `ReferenceSRID` = NULL WHERE `ReferenceSRID` = 0;
UPDATE `samplerequestimport` SET `RequestFromID` = NULL WHERE `RequestFromID` = 0;
UPDATE `samplerequestimport` SET `SampleRequestStatusID` = NULL WHERE `SampleRequestStatusID` = 0;
UPDATE `samplerequestimport` SET `UrgencyID` = NULL WHERE `UrgencyID` = 0;
UPDATE `samplerequestimport` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `samplerequestimportassignment` SET `SampleRequestImportID` = NULL WHERE `SampleRequestImportID` = 0;
UPDATE `samplerequestimportassignment` SET `SampleRequestStatusID` = NULL WHERE `SampleRequestStatusID` = 0;
UPDATE `samplerequestimportassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `samplerequestimportdetail` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `samplerequestimportdetail` SET `BaranglistID` = NULL WHERE `BaranglistID` = 0;
UPDATE `samplerequestimportdetail` SET `GoodReceiptDetailID` = NULL WHERE `GoodReceiptDetailID` = 0;
UPDATE `samplerequestimportdetail` SET `ReqCompanyID` = NULL WHERE `ReqCompanyID` = 0;
UPDATE `samplerequestimportdetail` SET `SampleRequestDetailStatusID` = NULL WHERE `SampleRequestDetailStatusID` = 0;
UPDATE `samplerequestimportdetail` SET `SampleRequestImportID` = NULL WHERE `SampleRequestImportID` = 0;
UPDATE `samplerequestimportdetail` SET `SatuanID` = NULL WHERE `SatuanID` = 0;
UPDATE `samplerequestimportdetailassignment` SET `SampleRequestDetailID` = NULL WHERE `SampleRequestDetailID` = 0;
UPDATE `samplerequestimportdetailassignment` SET `SampleRequestDetailStatusID` = NULL WHERE `SampleRequestDetailStatusID` = 0;
UPDATE `samplerequestimportdetailassignment` SET `SampleRequestImportID` = NULL WHERE `SampleRequestImportID` = 0;
UPDATE `samplerequestimportdetailassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `samplerequestimportgoodsreceipt` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `samplerequestimportgoodsreceipt` SET `BarangListsID` = NULL WHERE `BarangListsID` = 0;
UPDATE `samplerequestimportgoodsreceipt` SET `SampleRequestImportDetailID` = NULL WHERE `SampleRequestImportDetailID` = 0;
UPDATE `samplerequestimportgoodsreceipt` SET `SampleRequestImportID` = NULL WHERE `SampleRequestImportID` = 0;
UPDATE `samplerequestimportgoodsreceipt` SET `SatuanID` = NULL WHERE `SatuanID` = 0;
UPDATE `specialreference` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `specialreferencehistory` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `specialreferencehistory` SET `SpecialReferenceID` = NULL WHERE `SpecialReferenceID` = 0;
UPDATE `specialreferencehistory` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `stockopname` SET `PackagingID` = NULL WHERE `PackagingID` = 0;
UPDATE `stockopname` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `stockopname` SET `ProductID` = NULL WHERE `ProductID` = 0;
UPDATE `stockopname` SET `StockOpnameBy` = NULL WHERE `StockOpnameBy` = 0;
UPDATE `stockopname` SET `UOMID` = NULL WHERE `UOMID` = 0;
UPDATE `stockopname` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `stockopname` SET `WarehouseID` = NULL WHERE `WarehouseID` = 0;
UPDATE `stockopname_product` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `stockopname_product` SET `UOMID` = NULL WHERE `UOMID` = 0;
UPDATE `stockopnamehistory` SET `PackagingID` = NULL WHERE `PackagingID` = 0;
UPDATE `stockopnamehistory` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `stockopnamehistory` SET `ProductID` = NULL WHERE `ProductID` = 0;
UPDATE `stockopnamehistory` SET `StockOpnameBy` = NULL WHERE `StockOpnameBy` = 0;
UPDATE `stockopnamehistory` SET `StockOpnameID` = NULL WHERE `StockOpnameID` = 0;
UPDATE `stockopnamehistory` SET `StockOpnameStatusID` = NULL WHERE `StockOpnameStatusID` = 0;
UPDATE `stockopnamehistory` SET `UOMID` = NULL WHERE `UOMID` = 0;
UPDATE `stockopnamehistory` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `stockopnamehistory` SET `WarehouseID` = NULL WHERE `WarehouseID` = 0;
UPDATE `successstory` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `successstory` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `successstory` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `successstory` SET `GroupDivisionID` = NULL WHERE `GroupDivisionID` = 0;
UPDATE `successstory` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `successstory` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `successstory` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `successstoryassignment` SET `SuccessStoryID` = NULL WHERE `SuccessStoryID` = 0;
UPDATE `successstoryassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `suratjalan` SET `CompanyCPID` = NULL WHERE `CompanyCPID` = 0;
UPDATE `suratjalan` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `suratjalan` SET `DeliveryID` = NULL WHERE `DeliveryID` = 0;
UPDATE `suratjalan` SET `LocationID` = NULL WHERE `LocationID` = 0;
UPDATE `suratjalan` SET `SampleOrderID` = NULL WHERE `SampleOrderID` = 0;
UPDATE `suratjalan` SET `UserIDCreatorSJ` = NULL WHERE `UserIDCreatorSJ` = 0;
UPDATE `suratjalan` SET `UserIDsales` = NULL WHERE `UserIDsales` = 0;
UPDATE `suratjalandetails` SET `ApplicationID` = NULL WHERE `ApplicationID` = 0;
UPDATE `suratjalandetails` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `suratjalandetails` SET `BarangListID` = NULL WHERE `BarangListID` = 0;
UPDATE `suratjalandetails` SET `SampleOrderID` = NULL WHERE `SampleOrderID` = 0;
UPDATE `suratjalandetails` SET `SatuanID` = NULL WHERE `SatuanID` = 0;
UPDATE `suratjalandetails` SET `SuratJalanID` = NULL WHERE `SuratJalanID` = 0;
UPDATE `userbusinesstravelbranch` SET `BranchID` = NULL WHERE `BranchID` = 0;
UPDATE `userbusinesstravelbranch` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `userdetails` SET `BranchID` = NULL WHERE `BranchID` = 0;
UPDATE `userdetails` SET `DepartmentID` = NULL WHERE `DepartmentID` = 0;
UPDATE `userdetails` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `userdivision` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `userdivision` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `usereducation` SET `EducationID` = NULL WHERE `EducationID` = 0;
UPDATE `usereducation` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `userjob` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `userlabgroupdivision` SET `GroupDivisionID` = NULL WHERE `GroupDivisionID` = 0;
UPDATE `userlabgroupdivision` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `userprincipal` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `userprincipal` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `users` SET `BranchID` = NULL WHERE `BranchID` = 0;
UPDATE `users` SET `DepartmentID` = NULL WHERE `DepartmentID` = 0;
UPDATE `users` SET `HeadID` = NULL WHERE `HeadID` = 0;
UPDATE `users` SET `MaritalStatusID` = NULL WHERE `MaritalStatusID` = 0;
UPDATE `users` SET `RoleID` = NULL WHERE `RoleID` = 0;
UPDATE `usersperiode` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `userwarehouse` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `userwarehouse` SET `WarehouseID` = NULL WHERE `WarehouseID` = 0;
UPDATE `vehicle` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `vehicle` SET `UserIDOwner` = NULL WHERE `UserIDOwner` = 0;
UPDATE `vehicle` SET `VehicleBrandID` = NULL WHERE `VehicleBrandID` = 0;
UPDATE `vehicle` SET `VehicleBrandTypeID` = NULL WHERE `VehicleBrandTypeID` = 0;
UPDATE `vehicle` SET `VehicleColorID` = NULL WHERE `VehicleColorID` = 0;
UPDATE `vehicle` SET `VehicleFuelTypeID` = NULL WHERE `VehicleFuelTypeID` = 0;
UPDATE `vehicle` SET `VehicleTypeID` = NULL WHERE `VehicleTypeID` = 0;
UPDATE `vehicleassignment` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `vehicleassignment` SET `UserIDOwnerAfter` = NULL WHERE `UserIDOwnerAfter` = 0;
UPDATE `vehicleassignment` SET `UserIDOwnerBefore` = NULL WHERE `UserIDOwnerBefore` = 0;
UPDATE `vehicleassignment` SET `VehicleBrandIDAfter` = NULL WHERE `VehicleBrandIDAfter` = 0;
UPDATE `vehicleassignment` SET `VehicleBrandIDBefore` = NULL WHERE `VehicleBrandIDBefore` = 0;
UPDATE `vehicleassignment` SET `VehicleBrandTypeIDAfter` = NULL WHERE `VehicleBrandTypeIDAfter` = 0;
UPDATE `vehicleassignment` SET `VehicleBrandTypeIDBefore` = NULL WHERE `VehicleBrandTypeIDBefore` = 0;
UPDATE `vehicleassignment` SET `VehicleColorIDAfter` = NULL WHERE `VehicleColorIDAfter` = 0;
UPDATE `vehicleassignment` SET `VehicleColorIDBefore` = NULL WHERE `VehicleColorIDBefore` = 0;
UPDATE `vehicleassignment` SET `VehicleFuelTypeIDAfter` = NULL WHERE `VehicleFuelTypeIDAfter` = 0;
UPDATE `vehicleassignment` SET `VehicleFuelTypeIDBefore` = NULL WHERE `VehicleFuelTypeIDBefore` = 0;
UPDATE `vehicleassignment` SET `VehicleID` = NULL WHERE `VehicleID` = 0;
UPDATE `vehicleassignment` SET `VehicleStatusID` = NULL WHERE `VehicleStatusID` = 0;
UPDATE `vehicleassignment` SET `VehicleTypeIDAfter` = NULL WHERE `VehicleTypeIDAfter` = 0;
UPDATE `vehicleassignment` SET `VehicleTypeIDBefore` = NULL WHERE `VehicleTypeIDBefore` = 0;
UPDATE `vehiclebrandtype` SET `VehicleBrandID` = NULL WHERE `VehicleBrandID` = 0;
UPDATE `vehicleservicerequest` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `vehicleservicerequest` SET `UserIDOwner` = NULL WHERE `UserIDOwner` = 0;
UPDATE `vehicleservicerequest` SET `VehicleID` = NULL WHERE `VehicleID` = 0;
UPDATE `vehicleservicerequest` SET `VehicleServiceRequestStatusID` = NULL WHERE `VehicleServiceRequestStatusID` = 0;
UPDATE `vehicleservicerequestassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `vehicleservicerequestassignment` SET `VehicleServiceRequestID` = NULL WHERE `VehicleServiceRequestID` = 0;
UPDATE `vehicleservicerequestassignment` SET `VehicleServiceRequestStatusID` = NULL WHERE `VehicleServiceRequestStatusID` = 0;
UPDATE `vehicleservicerequestdetails` SET `VehicleServiceRequestDetailStatus` = NULL WHERE `VehicleServiceRequestDetailStatus` = 0;
UPDATE `vehicleservicerequestdetails` SET `VehicleServiceRequestID` = NULL WHERE `VehicleServiceRequestID` = 0;
UPDATE `vehicleservicerequestdetails` SET `VehicleServiceTypeID` = NULL WHERE `VehicleServiceTypeID` = 0;
UPDATE `vehicleservicerequestdetailsassigntment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `vehicleservicerequestdetailsassigntment` SET `VehicleServiceRequestDetailID` = NULL WHERE `VehicleServiceRequestDetailID` = 0;
UPDATE `vehicleservicerequestdetailsassigntment` SET `VehicleServiceRequestID` = NULL WHERE `VehicleServiceRequestID` = 0;
UPDATE `vehicleservicerequestdetailsassigntment` SET `VehicleServiceRequestStatusID` = NULL WHERE `VehicleServiceRequestStatusID` = 0;
UPDATE `visitplan` SET `CompanyCPID` = NULL WHERE `CompanyCPID` = 0;
UPDATE `visitplan` SET `CompanyID` = NULL WHERE `CompanyID` = 0;
UPDATE `visitplan` SET `DivisionID` = NULL WHERE `DivisionID` = 0;
UPDATE `visitplan` SET `ProjectID` = NULL WHERE `ProjectID` = 0;
UPDATE `visitplan` SET `UserIDInput` = NULL WHERE `UserIDInput` = 0;
UPDATE `visitplan` SET `UserIDSales` = NULL WHERE `UserIDSales` = 0;
UPDATE `visitplan` SET `UserIDVisitWith` = NULL WHERE `UserIDVisitWith` = 0;
UPDATE `visitplan` SET `VisitPlanStatusID` = NULL WHERE `VisitPlanStatusID` = 0;
UPDATE `visitplan` SET `VisitPrincipalCPID` = NULL WHERE `VisitPrincipalCPID` = 0;
UPDATE `visitplan` SET `VisitingPrincipalID` = NULL WHERE `VisitingPrincipalID` = 0;
UPDATE `visitplanassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `visitplanassignment` SET `VisitPlanID` = NULL WHERE `VisitPlanID` = 0;
UPDATE `visitplanassignment` SET `VisitPlanStatusID` = NULL WHERE `VisitPlanStatusID` = 0;
UPDATE `visitplancompanycpdetail` SET `CompanyCPID` = NULL WHERE `CompanyCPID` = 0;
UPDATE `visitplancompanycpdetail` SET `VisitPlanID` = NULL WHERE `VisitPlanID` = 0;
UPDATE `visitplandetail` SET `ActionID` = NULL WHERE `ActionID` = 0;
UPDATE `visitplandetail` SET `BarangID` = NULL WHERE `BarangID` = 0;
UPDATE `visitplandetail` SET `PrincipalID` = NULL WHERE `PrincipalID` = 0;
UPDATE `visitplandetail` SET `ProjectID` = NULL WHERE `ProjectID` = 0;
UPDATE `visitplandetail` SET `VisitActionStatusID` = NULL WHERE `VisitActionStatusID` = 0;
UPDATE `visitplandetail` SET `VisitPlanID` = NULL WHERE `VisitPlanID` = 0;
UPDATE `visitplandetailassignment` SET `UserID` = NULL WHERE `UserID` = 0;
UPDATE `visitplandetailassignment` SET `VisitActionStatusID` = NULL WHERE `VisitActionStatusID` = 0;
UPDATE `visitplandetailassignment` SET `VisitPlanDetailID` = NULL WHERE `VisitPlanDetailID` = 0;
UPDATE `visitplandetailassignment` SET `VisitPlanID` = NULL WHERE `VisitPlanID` = 0;
UPDATE `visitplandetailassignment` SET `VisitPlanStatusID` = NULL WHERE `VisitPlanStatusID` = 0;
UPDATE `visitplanfrienddetail` SET `UserIDVisitWith` = NULL WHERE `UserIDVisitWith` = 0;
UPDATE `visitplanfrienddetail` SET `VisitPlanID` = NULL WHERE `VisitPlanID` = 0;
UPDATE `visitplanlink` SET `VisitPlanID` = NULL WHERE `VisitPlanID` = 0;
UPDATE `visitplanprincipalvisitdetail` SET `VisitPlanID` = NULL WHERE `VisitPlanID` = 0;
UPDATE `visitplanprincipalvisitdetail` SET `VisitingPrincipalCPID` = NULL WHERE `VisitingPrincipalCPID` = 0;
UPDATE `visitplanprincipalvisitdetail` SET `VisitingPrincipalID` = NULL WHERE `VisitingPrincipalID` = 0;
UPDATE `warehouse` SET `ParentID` = NULL WHERE `ParentID` = 0;

-- SECTION 6 - Normalise orphaned references to NULL (636 foreign-key columns)
-- >>> READ THIS <<<  Unlike section 5, these rows point at a parent row that no longer
-- exists. Nulling them DISCARDS the original value. Run audit_bukanmain_before_migrate.sql
-- first if you want to see what will be lost.
-- ---------------------------------------------------------------------
UPDATE `application` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `application` c LEFT JOIN `groupdivision` p ON c.`GroupDivisionID` = p.`ID` SET c.`GroupDivisionID` = NULL WHERE c.`GroupDivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `bank` c LEFT JOIN `quotationpricedesc` p ON c.`QuotationPriceDescID` = p.`ID` SET c.`QuotationPriceDescID` = NULL WHERE c.`QuotationPriceDescID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `bankdivision` c LEFT JOIN `bank` p ON c.`BankID` = p.`ID` SET c.`BankID` = NULL WHERE c.`BankID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `bankdivision` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `barang` c LEFT JOIN `category` p ON c.`CategoryID` = p.`ID` SET c.`CategoryID` = NULL WHERE c.`CategoryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `barang` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `barang` c LEFT JOIN `satuan` p ON c.`SatuanID` = p.`ID` SET c.`SatuanID` = NULL WHERE c.`SatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `barang` c LEFT JOIN `type` p ON c.`TypeID` = p.`ID` SET c.`TypeID` = NULL WHERE c.`TypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `baranglist` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `baranglist` c LEFT JOIN `barangliststatus` p ON c.`BarangListStatusID` = p.`ID` SET c.`BarangListStatusID` = NULL WHERE c.`BarangListStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `baranglist` c LEFT JOIN `sampleorderdetail` p ON c.`SampleOrderDetailID` = p.`ID` SET c.`SampleOrderDetailID` = NULL WHERE c.`SampleOrderDetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `baranglist` c LEFT JOIN `satuan` p ON c.`SatuanID` = p.`ID` SET c.`SatuanID` = NULL WHERE c.`SatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `baranglists` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `baranglists` c LEFT JOIN `satuan` p ON c.`SatuanID` = p.`ID` SET c.`SatuanID` = NULL WHERE c.`SatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `barangstockmin` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `barangstockmin` c LEFT JOIN `satuan` p ON c.`SatuanID` = p.`ID` SET c.`SatuanID` = NULL WHERE c.`SatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `budgetandtarget` c LEFT JOIN `budgetandtargetperiode` p ON c.`BudgetAndTargetPeriodeID` = p.`ID` SET c.`BudgetAndTargetPeriodeID` = NULL WHERE c.`BudgetAndTargetPeriodeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `budgetandtarget` c LEFT JOIN `budgetandtargetstatus` p ON c.`BudgetAndTargetStatusID` = p.`ID` SET c.`BudgetAndTargetStatusID` = NULL WHERE c.`BudgetAndTargetStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `budgetandtarget` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `budgetandtarget` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `budgetandtarget` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `budgetandtarget` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `budgetandtarget` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `budgetandtargetassignment` c LEFT JOIN `budgetandtarget` p ON c.`BudgetAndTargetID` = p.`ID` SET c.`BudgetAndTargetID` = NULL WHERE c.`BudgetAndTargetID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `budgetandtargetassignment` c LEFT JOIN `budgetandtargetstatus` p ON c.`BudgetAndTargetStatusID` = p.`ID` SET c.`BudgetAndTargetStatusID` = NULL WHERE c.`BudgetAndTargetStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `budgetandtargetassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `comissionpercentage` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `company` c LEFT JOIN `branch` p ON c.`BranchID` = p.`ID` SET c.`BranchID` = NULL WHERE c.`BranchID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `company` c LEFT JOIN `companycategory` p ON c.`CompanyCategoryID` = p.`ID` SET c.`CompanyCategoryID` = NULL WHERE c.`CompanyCategoryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `company` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `company` c LEFT JOIN `industry` p ON c.`IndustryID` = p.`ID` SET c.`IndustryID` = NULL WHERE c.`IndustryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `company` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyaccessothers` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyaccessothers` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companycategory` c LEFT JOIN `groupdivision` p ON c.`GroupDivID` = p.`ID` SET c.`GroupDivID` = NULL WHERE c.`GroupDivID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companycategorylist` c LEFT JOIN `companycategory` p ON c.`CompanyCategoryID` = p.`ID` SET c.`CompanyCategoryID` = NULL WHERE c.`CompanyCategoryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companycategorylist` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companycp` c LEFT JOIN `addresstype` p ON c.`AddressType` = p.`ID` SET c.`AddressType` = NULL WHERE c.`AddressType` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companycp` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companycpassignment` c LEFT JOIN `addresstype` p ON c.`AddressType` = p.`ID` SET c.`AddressType` = NULL WHERE c.`AddressType` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companycpassignment` c LEFT JOIN `companycp` p ON c.`CompanyCPID` = p.`ID` SET c.`CompanyCPID` = NULL WHERE c.`CompanyCPID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companycpassignment` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companycpassignment` c LEFT JOIN `users` p ON c.`UsersID` = p.`ID` SET c.`UsersID` = NULL WHERE c.`UsersID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyhistory` c LEFT JOIN `branch` p ON c.`BranchID` = p.`ID` SET c.`BranchID` = NULL WHERE c.`BranchID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyhistory` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyhistory` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyhistory` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyhistory` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyindustry` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyindustry` c LEFT JOIN `industry` p ON c.`IndustryID` = p.`ID` SET c.`IndustryID` = NULL WHERE c.`IndustryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduct` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduct` c LEFT JOIN `barang` p ON c.`CCBarangID` = p.`ID` SET c.`CCBarangID` = NULL WHERE c.`CCBarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduct` c LEFT JOIN `satuan` p ON c.`CCPriceSatuanID` = p.`ID` SET c.`CCPriceSatuanID` = NULL WHERE c.`CCPriceSatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduct` c LEFT JOIN `principal` p ON c.`CCPrincipalID` = p.`ID` SET c.`CCPrincipalID` = NULL WHERE c.`CCPrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduct` c LEFT JOIN `satuan` p ON c.`CCVolumeSatuanID` = p.`ID` SET c.`CCVolumeSatuanID` = NULL WHERE c.`CCVolumeSatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduct` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduct` c LEFT JOIN `barang` p ON c.`CompetitorBarangID` = p.`ID` SET c.`CompetitorBarangID` = NULL WHERE c.`CompetitorBarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduct` c LEFT JOIN `satuan` p ON c.`CompetitorPriceSatuanID` = p.`ID` SET c.`CompetitorPriceSatuanID` = NULL WHERE c.`CompetitorPriceSatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduct` c LEFT JOIN `principal` p ON c.`CompetitorPrincipalID` = p.`ID` SET c.`CompetitorPrincipalID` = NULL WHERE c.`CompetitorPrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduct` c LEFT JOIN `satuan` p ON c.`CompetitorVolumeSatuanID` = p.`ID` SET c.`CompetitorVolumeSatuanID` = NULL WHERE c.`CompetitorVolumeSatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduct` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductapplication` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductapplication` c LEFT JOIN `application` p ON c.`ProductApplicationID` = p.`ID` SET c.`ProductApplicationID` = NULL WHERE c.`ProductApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductassignment` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductassignment` c LEFT JOIN `barang` p ON c.`CCBarangID` = p.`ID` SET c.`CCBarangID` = NULL WHERE c.`CCBarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductassignment` c LEFT JOIN `satuan` p ON c.`CCPriceSatuanID` = p.`ID` SET c.`CCPriceSatuanID` = NULL WHERE c.`CCPriceSatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductassignment` c LEFT JOIN `principal` p ON c.`CCPrincipalID` = p.`ID` SET c.`CCPrincipalID` = NULL WHERE c.`CCPrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductassignment` c LEFT JOIN `satuan` p ON c.`CCVolumeSatuanID` = p.`ID` SET c.`CCVolumeSatuanID` = NULL WHERE c.`CCVolumeSatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductassignment` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductassignment` c LEFT JOIN `companyproduct` p ON c.`CompanyProductID` = p.`ID` SET c.`CompanyProductID` = NULL WHERE c.`CompanyProductID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductassignment` c LEFT JOIN `barang` p ON c.`CompetitorBarangID` = p.`ID` SET c.`CompetitorBarangID` = NULL WHERE c.`CompetitorBarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductassignment` c LEFT JOIN `satuan` p ON c.`CompetitorPriceSatuanID` = p.`ID` SET c.`CompetitorPriceSatuanID` = NULL WHERE c.`CompetitorPriceSatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductassignment` c LEFT JOIN `principal` p ON c.`CompetitorPrincipalID` = p.`ID` SET c.`CompetitorPrincipalID` = NULL WHERE c.`CompetitorPrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductassignment` c LEFT JOIN `satuan` p ON c.`CompetitorVolumeSatuanID` = p.`ID` SET c.`CompetitorVolumeSatuanID` = NULL WHERE c.`CompetitorVolumeSatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductassignment` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductassignment` c LEFT JOIN `users` p ON c.`UsersID` = p.`ID` SET c.`UsersID` = NULL WHERE c.`UsersID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductcategory` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductcategory` c LEFT JOIN `category` p ON c.`ProductCategoryID` = p.`ID` SET c.`ProductCategoryID` = NULL WHERE c.`ProductCategoryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduction` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduction` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduction` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproduction` c LEFT JOIN `satuan` p ON c.`VolumeSatuanID` = p.`ID` SET c.`VolumeSatuanID` = NULL WHERE c.`VolumeSatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductionassignment` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductionassignment` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductionassignment` c LEFT JOIN `companyproduction` p ON c.`CompanyProductionID` = p.`ID` SET c.`CompanyProductionID` = NULL WHERE c.`CompanyProductionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductionassignment` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductionassignment` c LEFT JOIN `users` p ON c.`UsersID` = p.`ID` SET c.`UsersID` = NULL WHERE c.`UsersID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproductionassignment` c LEFT JOIN `satuan` p ON c.`VolumeSatuanID` = p.`ID` SET c.`VolumeSatuanID` = NULL WHERE c.`VolumeSatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproject` c LEFT JOIN `companycp` p ON c.`CompanyCP` = p.`ID` SET c.`CompanyCP` = NULL WHERE c.`CompanyCP` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproject` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproject` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproject` c LEFT JOIN `industry` p ON c.`IndustryID` = p.`ID` SET c.`IndustryID` = NULL WHERE c.`IndustryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproject` c LEFT JOIN `companyproject` p ON c.`ProjectID` = p.`ID` SET c.`ProjectID` = NULL WHERE c.`ProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproject` c LEFT JOIN `companyprojectpriority` p ON c.`ProjectPriority` = p.`ID` SET c.`ProjectPriority` = NULL WHERE c.`ProjectPriority` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproject` c LEFT JOIN `companyprojectstatus` p ON c.`ProjectStatusID` = p.`ID` SET c.`ProjectStatusID` = NULL WHERE c.`ProjectStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproject` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyproject` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectassignment` c LEFT JOIN `companyprojectdetailcc` p ON c.`CompanyProjectDetailCCID` = p.`ID` SET c.`CompanyProjectDetailCCID` = NULL WHERE c.`CompanyProjectDetailCCID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectassignment` c LEFT JOIN `companyprojectdetails` p ON c.`CompanyProjectDetailID` = p.`ID` SET c.`CompanyProjectDetailID` = NULL WHERE c.`CompanyProjectDetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectassignment` c LEFT JOIN `companyproject` p ON c.`CompanyProjectID` = p.`ID` SET c.`CompanyProjectID` = NULL WHERE c.`CompanyProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectassignment` c LEFT JOIN `companyprojectstatus` p ON c.`ProjectStatusID` = p.`ID` SET c.`ProjectStatusID` = NULL WHERE c.`ProjectStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectassignment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcc` c LEFT JOIN `companyproject` p ON c.`CompanyProjectID` = p.`ID` SET c.`CompanyProjectID` = NULL WHERE c.`CompanyProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcc` c LEFT JOIN `companyprojectdetails` p ON c.`DetailID` = p.`ID` SET c.`DetailID` = NULL WHERE c.`DetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcc` c LEFT JOIN `companyprojectdetailstatusreason` p ON c.`ItemReasonID` = p.`ID` SET c.`ItemReasonID` = NULL WHERE c.`ItemReasonID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcc` c LEFT JOIN `companyprojectdetailstatus` p ON c.`ItemStatusID` = p.`ID` SET c.`ItemStatusID` = NULL WHERE c.`ItemStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcc` c LEFT JOIN `pricetype` p ON c.`PriceTypeID` = p.`ID` SET c.`PriceTypeID` = NULL WHERE c.`PriceTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcc` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcc` c LEFT JOIN `barang` p ON c.`ProductID` = p.`ID` SET c.`ProductID` = NULL WHERE c.`ProductID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcc` c LEFT JOIN `companyprojectstatus` p ON c.`ProjectStatusID` = p.`ID` SET c.`ProjectStatusID` = NULL WHERE c.`ProjectStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcc` c LEFT JOIN `quantitytype` p ON c.`QtTypeID` = p.`ID` SET c.`QtTypeID` = NULL WHERE c.`QtTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcc` c LEFT JOIN `satuan` p ON c.`SatuanID` = p.`ID` SET c.`SatuanID` = NULL WHERE c.`SatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailccassignment` c LEFT JOIN `companyproject` p ON c.`CompanyProjectID` = p.`ID` SET c.`CompanyProjectID` = NULL WHERE c.`CompanyProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailccassignment` c LEFT JOIN `companyprojectdetailcc` p ON c.`DetailCCID` = p.`ID` SET c.`DetailCCID` = NULL WHERE c.`DetailCCID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailccassignment` c LEFT JOIN `companyprojectdetails` p ON c.`DetailID` = p.`ID` SET c.`DetailID` = NULL WHERE c.`DetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailccassignment` c LEFT JOIN `pricetype` p ON c.`PriceTypeID` = p.`ID` SET c.`PriceTypeID` = NULL WHERE c.`PriceTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailccassignment` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailccassignment` c LEFT JOIN `barang` p ON c.`ProductID` = p.`ID` SET c.`ProductID` = NULL WHERE c.`ProductID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailccassignment` c LEFT JOIN `quantitytype` p ON c.`QtTypeID` = p.`ID` SET c.`QtTypeID` = NULL WHERE c.`QtTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailccassignment` c LEFT JOIN `satuan` p ON c.`SatuanID` = p.`ID` SET c.`SatuanID` = NULL WHERE c.`SatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailccassignment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcomp` c LEFT JOIN `companyproject` p ON c.`CompanyProjectID` = p.`ID` SET c.`CompanyProjectID` = NULL WHERE c.`CompanyProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcomp` c LEFT JOIN `companyprojectdetails` p ON c.`DetailID` = p.`ID` SET c.`DetailID` = NULL WHERE c.`DetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcomp` c LEFT JOIN `pricetype` p ON c.`PriceTypeIDComp` = p.`ID` SET c.`PriceTypeIDComp` = NULL WHERE c.`PriceTypeIDComp` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcomp` c LEFT JOIN `principal` p ON c.`PrincipalIDComp` = p.`ID` SET c.`PrincipalIDComp` = NULL WHERE c.`PrincipalIDComp` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcomp` c LEFT JOIN `barang` p ON c.`ProductIDComp` = p.`ID` SET c.`ProductIDComp` = NULL WHERE c.`ProductIDComp` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcomp` c LEFT JOIN `quantitytype` p ON c.`QtTypeIDComp` = p.`ID` SET c.`QtTypeIDComp` = NULL WHERE c.`QtTypeIDComp` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcomp` c LEFT JOIN `satuan` p ON c.`SatuanIDComp` = p.`ID` SET c.`SatuanIDComp` = NULL WHERE c.`SatuanIDComp` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcompassignment` c LEFT JOIN `companyproject` p ON c.`CompanyProjectID` = p.`ID` SET c.`CompanyProjectID` = NULL WHERE c.`CompanyProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcompassignment` c LEFT JOIN `companyprojectdetailcomp` p ON c.`DetailCompID` = p.`ID` SET c.`DetailCompID` = NULL WHERE c.`DetailCompID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcompassignment` c LEFT JOIN `companyprojectdetails` p ON c.`DetailID` = p.`ID` SET c.`DetailID` = NULL WHERE c.`DetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcompassignment` c LEFT JOIN `pricetype` p ON c.`PriceTypeIDComp` = p.`ID` SET c.`PriceTypeIDComp` = NULL WHERE c.`PriceTypeIDComp` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcompassignment` c LEFT JOIN `principal` p ON c.`PrincipalIDComp` = p.`ID` SET c.`PrincipalIDComp` = NULL WHERE c.`PrincipalIDComp` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcompassignment` c LEFT JOIN `barang` p ON c.`ProductIDComp` = p.`ID` SET c.`ProductIDComp` = NULL WHERE c.`ProductIDComp` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcompassignment` c LEFT JOIN `quantitytype` p ON c.`QtTypeIDComp` = p.`ID` SET c.`QtTypeIDComp` = NULL WHERE c.`QtTypeIDComp` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcompassignment` c LEFT JOIN `satuan` p ON c.`SatuanIDComp` = p.`ID` SET c.`SatuanIDComp` = NULL WHERE c.`SatuanIDComp` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailcompassignment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetails` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetails` c LEFT JOIN `companyproject` p ON c.`CompanyProjectID` = p.`ID` SET c.`CompanyProjectID` = NULL WHERE c.`CompanyProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetails` c LEFT JOIN `companyprojectopportunitygroup` p ON c.`OpportunityGroupID` = p.`ID` SET c.`OpportunityGroupID` = NULL WHERE c.`OpportunityGroupID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetails` c LEFT JOIN `companyprojectstatus` p ON c.`ProjectStatusID` = p.`ID` SET c.`ProjectStatusID` = NULL WHERE c.`ProjectStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailsassignment` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailsassignment` c LEFT JOIN `companyproject` p ON c.`CompanyProjectID` = p.`ID` SET c.`CompanyProjectID` = NULL WHERE c.`CompanyProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailsassignment` c LEFT JOIN `companyprojectdetails` p ON c.`DetailID` = p.`ID` SET c.`DetailID` = NULL WHERE c.`DetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailsassignment` c LEFT JOIN `companyprojectopportunitygroup` p ON c.`OpportunityGroupID` = p.`ID` SET c.`OpportunityGroupID` = NULL WHERE c.`OpportunityGroupID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailsassignment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailstatusassignment` c LEFT JOIN `companyproject` p ON c.`CompanyProjectID` = p.`ID` SET c.`CompanyProjectID` = NULL WHERE c.`CompanyProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailstatusassignment` c LEFT JOIN `companyprojectdetailcc` p ON c.`DetailCCID` = p.`ID` SET c.`DetailCCID` = NULL WHERE c.`DetailCCID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailstatusassignment` c LEFT JOIN `companyprojectdetails` p ON c.`DetailID` = p.`ID` SET c.`DetailID` = NULL WHERE c.`DetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailstatusassignment` c LEFT JOIN `companyprojectdetailstatusreason` p ON c.`ItemReasonID` = p.`ID` SET c.`ItemReasonID` = NULL WHERE c.`ItemReasonID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailstatusassignment` c LEFT JOIN `companyprojectdetailstatus` p ON c.`ItemStatusID` = p.`ID` SET c.`ItemStatusID` = NULL WHERE c.`ItemStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailstatusassignment` c LEFT JOIN `companyprojectstatus` p ON c.`ProjectStatusID` = p.`ID` SET c.`ProjectStatusID` = NULL WHERE c.`ProjectStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailstatusassignment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectdetailstatusreason` c LEFT JOIN `companyprojectdetailstatus` p ON c.`StatusID` = p.`ID` SET c.`StatusID` = NULL WHERE c.`StatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectheaderassignment` c LEFT JOIN `companycp` p ON c.`CompanyCP` = p.`ID` SET c.`CompanyCP` = NULL WHERE c.`CompanyCP` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectheaderassignment` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectheaderassignment` c LEFT JOIN `companyproject` p ON c.`CompanyProjectID` = p.`ID` SET c.`CompanyProjectID` = NULL WHERE c.`CompanyProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectheaderassignment` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectheaderassignment` c LEFT JOIN `industry` p ON c.`IndustryID` = p.`ID` SET c.`IndustryID` = NULL WHERE c.`IndustryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectheaderassignment` c LEFT JOIN `companyproject` p ON c.`ProjectID` = p.`ID` SET c.`ProjectID` = NULL WHERE c.`ProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectheaderassignment` c LEFT JOIN `companyprojectpriority` p ON c.`ProjectPriority` = p.`ID` SET c.`ProjectPriority` = NULL WHERE c.`ProjectPriority` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectheaderassignment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `companyprojectheaderassignment` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complain` c LEFT JOIN `companycp` p ON c.`CompanyCPID` = p.`ID` SET c.`CompanyCPID` = NULL WHERE c.`CompanyCPID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complain` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complain` c LEFT JOIN `complainreason` p ON c.`ComplainReasonID` = p.`ID` SET c.`ComplainReasonID` = NULL WHERE c.`ComplainReasonID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complain` c LEFT JOIN `complainstatus` p ON c.`ComplainStatusID` = p.`ID` SET c.`ComplainStatusID` = NULL WHERE c.`ComplainStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complain` c LEFT JOIN `complaintype` p ON c.`ComplainTypeID` = p.`ID` SET c.`ComplainTypeID` = NULL WHERE c.`ComplainTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complain` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complain` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complain` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainassignment` c LEFT JOIN `complain` p ON c.`ComplainID` = p.`ID` SET c.`ComplainID` = NULL WHERE c.`ComplainID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainassignment` c LEFT JOIN `complainstatus` p ON c.`ComplainStatusID` = p.`ID` SET c.`ComplainStatusID` = NULL WHERE c.`ComplainStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetails` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetails` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetails` c LEFT JOIN `complaindetailsstatus` p ON c.`ComplainDetailsStatusID` = p.`ID` SET c.`ComplainDetailsStatusID` = NULL WHERE c.`ComplainDetailsStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetails` c LEFT JOIN `complain` p ON c.`ComplainID` = p.`ID` SET c.`ComplainID` = NULL WHERE c.`ComplainID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetails` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetails` c LEFT JOIN `satuan` p ON c.`SatuanComplainQuantityID` = p.`ID` SET c.`SatuanComplainQuantityID` = NULL WHERE c.`SatuanComplainQuantityID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetails` c LEFT JOIN `quotationpack` p ON c.`SatuanPackingID` = p.`ID` SET c.`SatuanPackingID` = NULL WHERE c.`SatuanPackingID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetails` c LEFT JOIN `satuan` p ON c.`SatuanUnitPriceUSD` = p.`ID` SET c.`SatuanUnitPriceUSD` = NULL WHERE c.`SatuanUnitPriceUSD` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetailsaction` c LEFT JOIN `complaindetails` p ON c.`ComplainDetailsID` = p.`ID` SET c.`ComplainDetailsID` = NULL WHERE c.`ComplainDetailsID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetailsaction` c LEFT JOIN `complaindetailsstatus` p ON c.`ComplainDetailsStatusID` = p.`ID` SET c.`ComplainDetailsStatusID` = NULL WHERE c.`ComplainDetailsStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetailsaction` c LEFT JOIN `complain` p ON c.`ComplainID` = p.`ID` SET c.`ComplainID` = NULL WHERE c.`ComplainID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetailsaction` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetailsactionassignment` c LEFT JOIN `complaindetailsaction` p ON c.`ComplainDetailsActionID` = p.`ID` SET c.`ComplainDetailsActionID` = NULL WHERE c.`ComplainDetailsActionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetailsactionassignment` c LEFT JOIN `complaindetails` p ON c.`ComplainDetailsID` = p.`ID` SET c.`ComplainDetailsID` = NULL WHERE c.`ComplainDetailsID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetailsactionassignment` c LEFT JOIN `complaindetailsstatus` p ON c.`ComplainDetailsStatusID` = p.`ID` SET c.`ComplainDetailsStatusID` = NULL WHERE c.`ComplainDetailsStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetailsactionassignment` c LEFT JOIN `complain` p ON c.`ComplainID` = p.`ID` SET c.`ComplainID` = NULL WHERE c.`ComplainID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetailsactionassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetailsassignment` c LEFT JOIN `complaindetails` p ON c.`ComplainDetailsID` = p.`ID` SET c.`ComplainDetailsID` = NULL WHERE c.`ComplainDetailsID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetailsassignment` c LEFT JOIN `complaindetailsstatus` p ON c.`ComplainDetailsStatusID` = p.`ID` SET c.`ComplainDetailsStatusID` = NULL WHERE c.`ComplainDetailsStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetailsassignment` c LEFT JOIN `complain` p ON c.`ComplainID` = p.`ID` SET c.`ComplainID` = NULL WHERE c.`ComplainID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaindetailsassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitem` c LEFT JOIN `complainitemstatus` p ON c.`ComplainStatusID` = p.`ID` SET c.`ComplainStatusID` = NULL WHERE c.`ComplainStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitem` c LEFT JOIN `complainitemtype` p ON c.`ComplainTypeID` = p.`ID` SET c.`ComplainTypeID` = NULL WHERE c.`ComplainTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitem` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitem` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemassignment` c LEFT JOIN `complainitem` p ON c.`ComplainItemID` = p.`ID` SET c.`ComplainItemID` = NULL WHERE c.`ComplainItemID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemassignment` c LEFT JOIN `complainitemstatus` p ON c.`ComplainItemStatusID` = p.`ID` SET c.`ComplainItemStatusID` = NULL WHERE c.`ComplainItemStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemassignment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetails` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetails` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetails` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetails` c LEFT JOIN `complaindetailsstatus` p ON c.`ComplainDetailStatusID` = p.`ID` SET c.`ComplainDetailStatusID` = NULL WHERE c.`ComplainDetailStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetails` c LEFT JOIN `complainitem` p ON c.`ComplainItemID` = p.`ID` SET c.`ComplainItemID` = NULL WHERE c.`ComplainItemID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetails` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetails` c LEFT JOIN `industry` p ON c.`IndustryID` = p.`ID` SET c.`IndustryID` = NULL WHERE c.`IndustryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetails` c LEFT JOIN `packing` p ON c.`PackingMonth` = p.`ID` SET c.`PackingMonth` = NULL WHERE c.`PackingMonth` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetails` c LEFT JOIN `packing` p ON c.`PackingYear` = p.`ID` SET c.`PackingYear` = NULL WHERE c.`PackingYear` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetailsaction` c LEFT JOIN `complainitem` p ON c.`ComplainID` = p.`ID` SET c.`ComplainID` = NULL WHERE c.`ComplainID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetailsaction` c LEFT JOIN `complainitemstatus` p ON c.`ComplainStatusID` = p.`ID` SET c.`ComplainStatusID` = NULL WHERE c.`ComplainStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetailsaction` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetailsactionassignment` c LEFT JOIN `complainitem` p ON c.`ComplainItemID` = p.`ID` SET c.`ComplainItemID` = NULL WHERE c.`ComplainItemID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetailsactionassignment` c LEFT JOIN `complainitemstatus` p ON c.`ComplainItemStatusID` = p.`ID` SET c.`ComplainItemStatusID` = NULL WHERE c.`ComplainItemStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetailsactionassignment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetailslot` c LEFT JOIN `complainitemdetails` p ON c.`ComplainItemDetailsID` = p.`ID` SET c.`ComplainItemDetailsID` = NULL WHERE c.`ComplainItemDetailsID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetailslot` c LEFT JOIN `complainitem` p ON c.`ComplainItemID` = p.`ID` SET c.`ComplainItemID` = NULL WHERE c.`ComplainItemID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetailslot` c LEFT JOIN `packing` p ON c.`PackagingID` = p.`ID` SET c.`PackagingID` = NULL WHERE c.`PackagingID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetailslotassignment` c LEFT JOIN `complainitemdetails` p ON c.`ComplainItemDetailsID` = p.`ID` SET c.`ComplainItemDetailsID` = NULL WHERE c.`ComplainItemDetailsID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetailslotassignment` c LEFT JOIN `complainitemdetailslot` p ON c.`ComplainItemDetailsLotID` = p.`ID` SET c.`ComplainItemDetailsLotID` = NULL WHERE c.`ComplainItemDetailsLotID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetailslotassignment` c LEFT JOIN `complainitem` p ON c.`ComplainItemID` = p.`ID` SET c.`ComplainItemID` = NULL WHERE c.`ComplainItemID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complainitemdetailslotassignment` c LEFT JOIN `packing` p ON c.`PackagingID` = p.`ID` SET c.`PackagingID` = NULL WHERE c.`PackagingID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplier` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplier` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplier` c LEFT JOIN `complaintosuppliertype` p ON c.`ComplainItemTypeID` = p.`ID` SET c.`ComplainItemTypeID` = NULL WHERE c.`ComplainItemTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplier` c LEFT JOIN `complaintosupplierstatus` p ON c.`ComplainStatusID` = p.`ID` SET c.`ComplainStatusID` = NULL WHERE c.`ComplainStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplier` c LEFT JOIN `complaintype` p ON c.`ComplainTypeID` = p.`ID` SET c.`ComplainTypeID` = NULL WHERE c.`ComplainTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplier` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplier` c LEFT JOIN `industry` p ON c.`IndustryID` = p.`ID` SET c.`IndustryID` = NULL WHERE c.`IndustryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplier` c LEFT JOIN `packing` p ON c.`PackingMonth` = p.`ID` SET c.`PackingMonth` = NULL WHERE c.`PackingMonth` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplier` c LEFT JOIN `packing` p ON c.`PackingYear` = p.`ID` SET c.`PackingYear` = NULL WHERE c.`PackingYear` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplier` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplier` c LEFT JOIN `product` p ON c.`ProductID` = p.`ID` SET c.`ProductID` = NULL WHERE c.`ProductID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplier` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplier` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplierassignment` c LEFT JOIN `complaintosupplier` p ON c.`ComplainID` = p.`ID` SET c.`ComplainID` = NULL WHERE c.`ComplainID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplierassignment` c LEFT JOIN `complaintosupplierstatus` p ON c.`ComplainStatusID` = p.`ID` SET c.`ComplainStatusID` = NULL WHERE c.`ComplainStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplierassignment` c LEFT JOIN `department` p ON c.`DepartmentID` = p.`ID` SET c.`DepartmentID` = NULL WHERE c.`DepartmentID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplierassignment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplierdetailsaction` c LEFT JOIN `complaintosupplier` p ON c.`ComplainID` = p.`ID` SET c.`ComplainID` = NULL WHERE c.`ComplainID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplierdetailsaction` c LEFT JOIN `complaintosupplierstatus` p ON c.`ComplainStatusID` = p.`ID` SET c.`ComplainStatusID` = NULL WHERE c.`ComplainStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplierdetailsaction` c LEFT JOIN `department` p ON c.`DepartementID` = p.`ID` SET c.`DepartementID` = NULL WHERE c.`DepartementID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplierdetailsaction` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplierdetailsactionassignment` c LEFT JOIN `complaintosupplier` p ON c.`ComplainID` = p.`ID` SET c.`ComplainID` = NULL WHERE c.`ComplainID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplierdetailsactionassignment` c LEFT JOIN `complaintosupplierstatus` p ON c.`ComplainStatusID` = p.`ID` SET c.`ComplainStatusID` = NULL WHERE c.`ComplainStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplierdetailsactionassignment` c LEFT JOIN `department` p ON c.`DepartmentID` = p.`ID` SET c.`DepartmentID` = NULL WHERE c.`DepartmentID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `complaintosupplierdetailsactionassignment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `division` c LEFT JOIN `groupdivision` p ON c.`GroupDivisionID` = p.`ID` SET c.`GroupDivisionID` = NULL WHERE c.`GroupDivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `documentgroupdivision` c LEFT JOIN `documentupload` p ON c.`DocID` = p.`ID` SET c.`DocID` = NULL WHERE c.`DocID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `documentgroupdivision` c LEFT JOIN `groupdivision` p ON c.`GroupDivID` = p.`ID` SET c.`GroupDivID` = NULL WHERE c.`GroupDivID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `documentupload` c LEFT JOIN `documentcategory` p ON c.`DocumentCategoryID` = p.`ID` SET c.`DocumentCategoryID` = NULL WHERE c.`DocumentCategoryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `documentupload` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `documentuploadinternal` c LEFT JOIN `documentcategory` p ON c.`DocumentCategoryID` = p.`ID` SET c.`DocumentCategoryID` = NULL WHERE c.`DocumentCategoryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `izin` c LEFT JOIN `izinstatus` p ON c.`IzinStatusID` = p.`ID` SET c.`IzinStatusID` = NULL WHERE c.`IzinStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `izin` c LEFT JOIN `izintype` p ON c.`IzinTypeID` = p.`ID` SET c.`IzinTypeID` = NULL WHERE c.`IzinTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `izin` c LEFT JOIN `izintypestatus` p ON c.`IzinTypeStatusID` = p.`ID` SET c.`IzinTypeStatusID` = NULL WHERE c.`IzinTypeStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `izin` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `izin` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `izinassignment` c LEFT JOIN `izin` p ON c.`IzinID` = p.`ID` SET c.`IzinID` = NULL WHERE c.`IzinID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `izinassignment` c LEFT JOIN `izinstatus` p ON c.`IzinStatusID` = p.`ID` SET c.`IzinStatusID` = NULL WHERE c.`IzinStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `izinassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `izintypestatus` c LEFT JOIN `izintype` p ON c.`IzinTypeID` = p.`ID` SET c.`IzinTypeID` = NULL WHERE c.`IzinTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequest` c LEFT JOIN `companycp` p ON c.`CompanyCPID` = p.`ID` SET c.`CompanyCPID` = NULL WHERE c.`CompanyCPID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequest` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequest` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequest` c LEFT JOIN `industry` p ON c.`IndustryID` = p.`ID` SET c.`IndustryID` = NULL WHERE c.`IndustryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequest` c LEFT JOIN `labworkrequestfeedbackstatus` p ON c.`LabWorkRequestFeedbackStatusID` = p.`ID` SET c.`LabWorkRequestFeedbackStatusID` = NULL WHERE c.`LabWorkRequestFeedbackStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequest` c LEFT JOIN `labworkrequeststatus` p ON c.`LabWorkRequestStatusID` = p.`ID` SET c.`LabWorkRequestStatusID` = NULL WHERE c.`LabWorkRequestStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequest` c LEFT JOIN `companyproject` p ON c.`ProjectID` = p.`ID` SET c.`ProjectID` = NULL WHERE c.`ProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequest` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequest` c LEFT JOIN `users` p ON c.`UserIDProjectInitiator` = p.`ID` SET c.`UserIDProjectInitiator` = NULL WHERE c.`UserIDProjectInitiator` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequest` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestassignment` c LEFT JOIN `labworkrequest` p ON c.`LabWorkRequestID` = p.`ID` SET c.`LabWorkRequestID` = NULL WHERE c.`LabWorkRequestID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestassignment` c LEFT JOIN `labworkrequeststatus` p ON c.`LabWorkRequestStatusID` = p.`ID` SET c.`LabWorkRequestStatusID` = NULL WHERE c.`LabWorkRequestStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestdetails` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestdetails` c LEFT JOIN `labworkrequestdetailstatus` p ON c.`LabWorkRequestDetailStatusID` = p.`ID` SET c.`LabWorkRequestDetailStatusID` = NULL WHERE c.`LabWorkRequestDetailStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestdetails` c LEFT JOIN `labworkrequest` p ON c.`LabWorkRequestID` = p.`ID` SET c.`LabWorkRequestID` = NULL WHERE c.`LabWorkRequestID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestdetails` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestdetails` c LEFT JOIN `companyprojectdetailcc` p ON c.`ProjectID` = p.`ID` SET c.`ProjectID` = NULL WHERE c.`ProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestdetails` c LEFT JOIN `companyprojectdetailcomp` p ON c.`ProjectIDComp` = p.`ID` SET c.`ProjectIDComp` = NULL WHERE c.`ProjectIDComp` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestdetails` c LEFT JOIN `satuan` p ON c.`SatuanIDUnitPrice` = p.`ID` SET c.`SatuanIDUnitPrice` = NULL WHERE c.`SatuanIDUnitPrice` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestdetails` c LEFT JOIN `satuan` p ON c.`SatuanIDVolume` = p.`ID` SET c.`SatuanIDVolume` = NULL WHERE c.`SatuanIDVolume` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestdetails` c LEFT JOIN `type` p ON c.`TypeID` = p.`ID` SET c.`TypeID` = NULL WHERE c.`TypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestdetailsassignment` c LEFT JOIN `labworkrequestdetails` p ON c.`LabWorkRequestDetailID` = p.`ID` SET c.`LabWorkRequestDetailID` = NULL WHERE c.`LabWorkRequestDetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestdetailsassignment` c LEFT JOIN `labworkrequestdetailstatus` p ON c.`LabWorkRequestDetailStatusID` = p.`ID` SET c.`LabWorkRequestDetailStatusID` = NULL WHERE c.`LabWorkRequestDetailStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestdetailsassignment` c LEFT JOIN `labworkrequest` p ON c.`LabWorkRequestID` = p.`ID` SET c.`LabWorkRequestID` = NULL WHERE c.`LabWorkRequestID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestdetailsassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `labworkrequestlink` c LEFT JOIN `labworkrequest` p ON c.`LabWorkRequestID` = p.`ID` SET c.`LabWorkRequestID` = NULL WHERE c.`LabWorkRequestID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `lembur` c LEFT JOIN `lemburstatus` p ON c.`LemburStatusID` = p.`ID` SET c.`LemburStatusID` = NULL WHERE c.`LemburStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `lembur` c LEFT JOIN `lemburtype` p ON c.`LemburTypeID` = p.`ID` SET c.`LemburTypeID` = NULL WHERE c.`LemburTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `lembur` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `lembur` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `lemburassignment` c LEFT JOIN `lembur` p ON c.`LemburID` = p.`ID` SET c.`LemburID` = NULL WHERE c.`LemburID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `lemburassignment` c LEFT JOIN `lemburstatus` p ON c.`LemburStatusID` = p.`ID` SET c.`LemburStatusID` = NULL WHERE c.`LemburStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `lemburassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `menu` c LEFT JOIN `menu` p ON c.`ParentID` = p.`ID` SET c.`ParentID` = NULL WHERE c.`ParentID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `news` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleave` c LEFT JOIN `onleavelimit` p ON c.`OnLeaveLimitID` = p.`ID` SET c.`OnLeaveLimitID` = NULL WHERE c.`OnLeaveLimitID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleave` c LEFT JOIN `onleavestatus` p ON c.`OnLeaveStatusID` = p.`ID` SET c.`OnLeaveStatusID` = NULL WHERE c.`OnLeaveStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleave` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleave` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleave` c LEFT JOIN `users` p ON c.`UserPengganti1` = p.`ID` SET c.`UserPengganti1` = NULL WHERE c.`UserPengganti1` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleave` c LEFT JOIN `users` p ON c.`UserPengganti2` = p.`ID` SET c.`UserPengganti2` = NULL WHERE c.`UserPengganti2` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleaveadditional` c LEFT JOIN `onleavelimit` p ON c.`OnLeaveLimitID` = p.`ID` SET c.`OnLeaveLimitID` = NULL WHERE c.`OnLeaveLimitID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleaveadditional` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleaveadditional` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleaveadditionalassignment` c LEFT JOIN `onleaveadditional` p ON c.`OnLeaveAdditionalID` = p.`ID` SET c.`OnLeaveAdditionalID` = NULL WHERE c.`OnLeaveAdditionalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleaveadditionalassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleaveassignment` c LEFT JOIN `onleave` p ON c.`OnLeaveID` = p.`ID` SET c.`OnLeaveID` = NULL WHERE c.`OnLeaveID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleaveassignment` c LEFT JOIN `onleavestatus` p ON c.`OnLeaveStatusID` = p.`ID` SET c.`OnLeaveStatusID` = NULL WHERE c.`OnLeaveStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `onleaveassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `packing` c LEFT JOIN `satuan` p ON c.`SatuanID` = p.`ID` SET c.`SatuanID` = NULL WHERE c.`SatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `potentialsales` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `potentialsales` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `potentialsales` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `potentialsaleshistory` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `potentialsaleshistory` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `potentialsaleshistory` c LEFT JOIN `potentialsales` p ON c.`PotentialSalesID` = p.`ID` SET c.`PotentialSalesID` = NULL WHERE c.`PotentialSalesID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `potentialsaleshistory` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `potentialsaleshistory` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `principalcp` c LEFT JOIN `addresstype` p ON c.`AddressType` = p.`ID` SET c.`AddressType` = NULL WHERE c.`AddressType` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `principalcp` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `principalcpassignment` c LEFT JOIN `addresstype` p ON c.`AddressType` = p.`ID` SET c.`AddressType` = NULL WHERE c.`AddressType` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `principalcpassignment` c LEFT JOIN `principalcp` p ON c.`PrincipalCPID` = p.`ID` SET c.`PrincipalCPID` = NULL WHERE c.`PrincipalCPID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `principalcpassignment` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `principalcpassignment` c LEFT JOIN `users` p ON c.`UsersID` = p.`ID` SET c.`UsersID` = NULL WHERE c.`UsersID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `principalfaq` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `principalfaqhistory` c LEFT JOIN `principalfaq` p ON c.`PrincipalFAQID` = p.`ID` SET c.`PrincipalFAQID` = NULL WHERE c.`PrincipalFAQID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `principalfaqhistory` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `printeditemfulfillment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `product` c LEFT JOIN `class` p ON c.`ClassID` = p.`ID` SET c.`ClassID` = NULL WHERE c.`ClassID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `product` c LEFT JOIN `packing` p ON c.`PackingID` = p.`ID` SET c.`PackingID` = NULL WHERE c.`PackingID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `product` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `productapplication` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `productapplication` c LEFT JOIN `barang` p ON c.`ProductID` = p.`ID` SET c.`ProductID` = NULL WHERE c.`ProductID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `productapplication` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `productcategory` c LEFT JOIN `category` p ON c.`CategoryID` = p.`ID` SET c.`CategoryID` = NULL WHERE c.`CategoryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `productcategory` c LEFT JOIN `barang` p ON c.`ProductID` = p.`ID` SET c.`ProductID` = NULL WHERE c.`ProductID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `productcategory` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `proposedcreditceiling` c LEFT JOIN `creditceilingstatus` p ON c.`CCStatusID` = p.`ID` SET c.`CCStatusID` = NULL WHERE c.`CCStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `proposedcreditceiling` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `proposedcreditceiling` c LEFT JOIN `justification` p ON c.`JustificationID` = p.`ID` SET c.`JustificationID` = NULL WHERE c.`JustificationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `proposedcreditceiling` c LEFT JOIN `quotationpaymentterm` p ON c.`QuotationPaymentTermApprovedID` = p.`ID` SET c.`QuotationPaymentTermApprovedID` = NULL WHERE c.`QuotationPaymentTermApprovedID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `proposedcreditceiling` c LEFT JOIN `quotationpaymentterm` p ON c.`QuotationPaymentTermID` = p.`ID` SET c.`QuotationPaymentTermID` = NULL WHERE c.`QuotationPaymentTermID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `proposedcreditceiling` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `proposedcreditceilinghistory` c LEFT JOIN `creditceilingstatus` p ON c.`CCStatusID` = p.`ID` SET c.`CCStatusID` = NULL WHERE c.`CCStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `proposedcreditceilinghistory` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `proposedcreditceilinghistory` c LEFT JOIN `justification` p ON c.`JustificationID` = p.`ID` SET c.`JustificationID` = NULL WHERE c.`JustificationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `proposedcreditceilinghistory` c LEFT JOIN `proposedcreditceiling` p ON c.`ProposedCCID` = p.`ID` SET c.`ProposedCCID` = NULL WHERE c.`ProposedCCID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `proposedcreditceilinghistory` c LEFT JOIN `quotationpaymentterm` p ON c.`QuotationPaymentTermApprovedID` = p.`ID` SET c.`QuotationPaymentTermApprovedID` = NULL WHERE c.`QuotationPaymentTermApprovedID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `proposedcreditceilinghistory` c LEFT JOIN `quotationpaymentterm` p ON c.`QuotationPaymentTermID` = p.`ID` SET c.`QuotationPaymentTermID` = NULL WHERE c.`QuotationPaymentTermID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `proposedcreditceilinghistory` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorder` c LEFT JOIN `purchaseorderstatus` p ON c.`PurchaseOrderStatusID` = p.`ID` SET c.`PurchaseOrderStatusID` = NULL WHERE c.`PurchaseOrderStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorder` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorderassignment` c LEFT JOIN `purchaseorder` p ON c.`PurchaseOrderID` = p.`ID` SET c.`PurchaseOrderID` = NULL WHERE c.`PurchaseOrderID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorderassignment` c LEFT JOIN `purchaseorderstatus` p ON c.`PurchaseOrderStatusID` = p.`ID` SET c.`PurchaseOrderStatusID` = NULL WHERE c.`PurchaseOrderStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorderassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorderdetails` c LEFT JOIN `packing` p ON c.`PackingID` = p.`ID` SET c.`PackingID` = NULL WHERE c.`PackingID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorderdetails` c LEFT JOIN `purchaseorderstatus` p ON c.`PurchaseOrderDetailStatusID` = p.`ID` SET c.`PurchaseOrderDetailStatusID` = NULL WHERE c.`PurchaseOrderDetailStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorderdetails` c LEFT JOIN `purchaseorder` p ON c.`PurchaseOrderID` = p.`ID` SET c.`PurchaseOrderID` = NULL WHERE c.`PurchaseOrderID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorderdetails` c LEFT JOIN `satuan` p ON c.`SatuanID` = p.`ID` SET c.`SatuanID` = NULL WHERE c.`SatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorderdetails` c LEFT JOIN `satuan` p ON c.`SatuanOrderQtyID` = p.`ID` SET c.`SatuanOrderQtyID` = NULL WHERE c.`SatuanOrderQtyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorderdetailsassignment` c LEFT JOIN `purchaseorderdetails` p ON c.`PurchaseOrderDetailID` = p.`ID` SET c.`PurchaseOrderDetailID` = NULL WHERE c.`PurchaseOrderDetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorderdetailsassignment` c LEFT JOIN `purchaseorder` p ON c.`PurchaseOrderID` = p.`ID` SET c.`PurchaseOrderID` = NULL WHERE c.`PurchaseOrderID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorderdetailsassignment` c LEFT JOIN `purchaseorderstatus` p ON c.`PurchaseOrderStatusID` = p.`ID` SET c.`PurchaseOrderStatusID` = NULL WHERE c.`PurchaseOrderStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorderdetailsassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `purchaseorderhargajual` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `companycp` p ON c.`CompanyCPID` = p.`ID` SET c.`CompanyCPID` = NULL WHERE c.`CompanyCPID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `companycp` p ON c.`DeliveryAddressID` = p.`ID` SET c.`DeliveryAddressID` = NULL WHERE c.`DeliveryAddressID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `companycp` p ON c.`InvoiceAddressID` = p.`ID` SET c.`InvoiceAddressID` = NULL WHERE c.`InvoiceAddressID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `quotationdeliverytime` p ON c.`QuotationDeliveryTimeID` = p.`ID` SET c.`QuotationDeliveryTimeID` = NULL WHERE c.`QuotationDeliveryTimeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `quotationfeedbackstatus` p ON c.`QuotationFeedbackStatusID` = p.`ID` SET c.`QuotationFeedbackStatusID` = NULL WHERE c.`QuotationFeedbackStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `quotationpaymentterm` p ON c.`QuotationPaymentTermID` = p.`ID` SET c.`QuotationPaymentTermID` = NULL WHERE c.`QuotationPaymentTermID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `quotationpricedesc` p ON c.`QuotationPriceDescID` = p.`ID` SET c.`QuotationPriceDescID` = NULL WHERE c.`QuotationPriceDescID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `quotationsalesterm` p ON c.`QuotationSalesTermID` = p.`ID` SET c.`QuotationSalesTermID` = NULL WHERE c.`QuotationSalesTermID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `quotationstatus` p ON c.`QuotationStatusID` = p.`ID` SET c.`QuotationStatusID` = NULL WHERE c.`QuotationStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `quotationstockavailability` p ON c.`QuotationStockAvailibilityID` = p.`ID` SET c.`QuotationStockAvailibilityID` = NULL WHERE c.`QuotationStockAvailibilityID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `quotationsubject` p ON c.`QuotationSubjectID` = p.`ID` SET c.`QuotationSubjectID` = NULL WHERE c.`QuotationSubjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `quotationtitle` p ON c.`QuotationTitleID` = p.`ID` SET c.`QuotationTitleID` = NULL WHERE c.`QuotationTitleID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `quotationtype` p ON c.`QuotationTypeID` = p.`ID` SET c.`QuotationTypeID` = NULL WHERE c.`QuotationTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `quotationvalidity` p ON c.`QuotationValidityID` = p.`ID` SET c.`QuotationValidityID` = NULL WHERE c.`QuotationValidityID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `quotation` p ON c.`ReferenceQuotationID` = p.`ID` SET c.`ReferenceQuotationID` = NULL WHERE c.`ReferenceQuotationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotation` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationassignment` c LEFT JOIN `quotation` p ON c.`QuotationID` = p.`ID` SET c.`QuotationID` = NULL WHERE c.`QuotationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationassignment` c LEFT JOIN `quotationstatus` p ON c.`QuotationStatusID` = p.`ID` SET c.`QuotationStatusID` = NULL WHERE c.`QuotationStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationdetails` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationdetails` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationdetails` c LEFT JOIN `packing` p ON c.`PackingID` = p.`ID` SET c.`PackingID` = NULL WHERE c.`PackingID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationdetails` c LEFT JOIN `companyprojectdetailcc` p ON c.`ProjectID` = p.`ID` SET c.`ProjectID` = NULL WHERE c.`ProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationdetails` c LEFT JOIN `quotationdetailstatus` p ON c.`QuotationDetailStatusID` = p.`ID` SET c.`QuotationDetailStatusID` = NULL WHERE c.`QuotationDetailStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationdetails` c LEFT JOIN `quotation` p ON c.`QuotationID` = p.`ID` SET c.`QuotationID` = NULL WHERE c.`QuotationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationdetails` c LEFT JOIN `quotationpack` p ON c.`QuotationPackID` = p.`ID` SET c.`QuotationPackID` = NULL WHERE c.`QuotationPackID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationdetails` c LEFT JOIN `satuan` p ON c.`SatuanID` = p.`ID` SET c.`SatuanID` = NULL WHERE c.`SatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationdetails` c LEFT JOIN `satuan` p ON c.`SatuanOrderQty` = p.`ID` SET c.`SatuanOrderQty` = NULL WHERE c.`SatuanOrderQty` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationdetailsassignment` c LEFT JOIN `quotationdetails` p ON c.`QuotationDetailID` = p.`ID` SET c.`QuotationDetailID` = NULL WHERE c.`QuotationDetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationdetailsassignment` c LEFT JOIN `quotationdetailstatus` p ON c.`QuotationDetailStatusID` = p.`ID` SET c.`QuotationDetailStatusID` = NULL WHERE c.`QuotationDetailStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationdetailsassignment` c LEFT JOIN `quotation` p ON c.`QuotationID` = p.`ID` SET c.`QuotationID` = NULL WHERE c.`QuotationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationdetailsassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `quotationlink` c LEFT JOIN `quotation` p ON c.`QuotationID` = p.`ID` SET c.`QuotationID` = NULL WHERE c.`QuotationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `reference` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `referencehistory` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `referencehistory` c LEFT JOIN `reference` p ON c.`ReferenceID` = p.`ID` SET c.`ReferenceID` = NULL WHERE c.`ReferenceID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `referencehistory` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `relabelhistory` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `rolegadget` c LEFT JOIN `gadget` p ON c.`GadgetID` = p.`ID` SET c.`GadgetID` = NULL WHERE c.`GadgetID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `rolegadget` c LEFT JOIN `role` p ON c.`RoleID` = p.`ID` SET c.`RoleID` = NULL WHERE c.`RoleID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `rolemenu` c LEFT JOIN `menu` p ON c.`MenuID` = p.`ID` SET c.`MenuID` = NULL WHERE c.`MenuID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `rolemenu` c LEFT JOIN `role` p ON c.`RoleID` = p.`ID` SET c.`RoleID` = NULL WHERE c.`RoleID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebate` c LEFT JOIN `quotationpaymentterm` p ON c.`CCPaymentTerm` = p.`ID` SET c.`CCPaymentTerm` = NULL WHERE c.`CCPaymentTerm` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebate` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebate` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebate` c LEFT JOIN `industry` p ON c.`IndustryID` = p.`ID` SET c.`IndustryID` = NULL WHERE c.`IndustryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebate` c LEFT JOIN `salesrebate` p ON c.`ReferenceRebateID` = p.`ID` SET c.`ReferenceRebateID` = NULL WHERE c.`ReferenceRebateID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebate` c LEFT JOIN `salesrebatestatus` p ON c.`SalesRebateStatusID` = p.`ID` SET c.`SalesRebateStatusID` = NULL WHERE c.`SalesRebateStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebate` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebate` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateassignment` c LEFT JOIN `salesrebate` p ON c.`SalesRebateID` = p.`ID` SET c.`SalesRebateID` = NULL WHERE c.`SalesRebateID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateassignment` c LEFT JOIN `salesrebatestatus` p ON c.`SalesRebateStatusID` = p.`ID` SET c.`SalesRebateStatusID` = NULL WHERE c.`SalesRebateStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateassignment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebatedetail` c LEFT JOIN `companycp` p ON c.`CompanyCPID` = p.`ID` SET c.`CompanyCPID` = NULL WHERE c.`CompanyCPID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebatedetail` c LEFT JOIN `salesrebate` p ON c.`SalesRebateID` = p.`ID` SET c.`SalesRebateID` = NULL WHERE c.`SalesRebateID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoice` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoice` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoice` c LEFT JOIN `industry` p ON c.`IndustryID` = p.`ID` SET c.`IndustryID` = NULL WHERE c.`IndustryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoice` c LEFT JOIN `salesrebate` p ON c.`SalesRebateID` = p.`ID` SET c.`SalesRebateID` = NULL WHERE c.`SalesRebateID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoice` c LEFT JOIN `salesrebateinvoicedetailstatus` p ON c.`SalesRebateInvoiceStatusID` = p.`ID` SET c.`SalesRebateInvoiceStatusID` = NULL WHERE c.`SalesRebateInvoiceStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoice` c LEFT JOIN `users` p ON c.`UserInput` = p.`ID` SET c.`UserInput` = NULL WHERE c.`UserInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoiceassignment` c LEFT JOIN `salesrebateinvoice` p ON c.`SalesRebateInvoiceID` = p.`ID` SET c.`SalesRebateInvoiceID` = NULL WHERE c.`SalesRebateInvoiceID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoiceassignment` c LEFT JOIN `salesrebateinvoicedetailstatus` p ON c.`SalesRebateInvoiceStatusID` = p.`ID` SET c.`SalesRebateInvoiceStatusID` = NULL WHERE c.`SalesRebateInvoiceStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoiceassignment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoicedetail` c LEFT JOIN `companycp` p ON c.`PaymentCPID` = p.`ID` SET c.`PaymentCPID` = NULL WHERE c.`PaymentCPID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoicedetail` c LEFT JOIN `salesrebate` p ON c.`SalesRebateID` = p.`ID` SET c.`SalesRebateID` = NULL WHERE c.`SalesRebateID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoicedetail` c LEFT JOIN `salesrebateinvoicedetailstatus` p ON c.`SalesRebateInvoiceDetailStatusID` = p.`ID` SET c.`SalesRebateInvoiceDetailStatusID` = NULL WHERE c.`SalesRebateInvoiceDetailStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoicedetail` c LEFT JOIN `salesrebateinvoice` p ON c.`SalesRebateInvoiceID` = p.`ID` SET c.`SalesRebateInvoiceID` = NULL WHERE c.`SalesRebateInvoiceID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `salesrebateinvoicepaymentdetail` c LEFT JOIN `salesrebateinvoicedetail` p ON c.`SalesRebateInvoiceDetailID` = p.`ID` SET c.`SalesRebateInvoiceDetailID` = NULL WHERE c.`SalesRebateInvoiceDetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `companycp` p ON c.`CompanyCPID` = p.`ID` SET c.`CompanyCPID` = NULL WHERE c.`CompanyCPID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `delivery` p ON c.`DeliveryID` = p.`ID` SET c.`DeliveryID` = NULL WHERE c.`DeliveryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `industry` p ON c.`IndustryID` = p.`ID` SET c.`IndustryID` = NULL WHERE c.`IndustryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `location` p ON c.`LocationID` = p.`ID` SET c.`LocationID` = NULL WHERE c.`LocationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `priority` p ON c.`PriorityID` = p.`ID` SET c.`PriorityID` = NULL WHERE c.`PriorityID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `companyproject` p ON c.`ProjectID` = p.`ID` SET c.`ProjectID` = NULL WHERE c.`ProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `sampleorder` p ON c.`ReferenceSOID` = p.`ID` SET c.`ReferenceSOID` = NULL WHERE c.`ReferenceSOID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `sampleorderby` p ON c.`SampleOrderByID` = p.`ID` SET c.`SampleOrderByID` = NULL WHERE c.`SampleOrderByID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `sampleorderfeedbackstatus` p ON c.`SampleOrderFeedbackStatusID` = p.`ID` SET c.`SampleOrderFeedbackStatusID` = NULL WHERE c.`SampleOrderFeedbackStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `sampleorderstatus` p ON c.`SampleOrderStatusID` = p.`ID` SET c.`SampleOrderStatusID` = NULL WHERE c.`SampleOrderStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorder` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderassignment` c LEFT JOIN `sampleorder` p ON c.`SampleOrderID` = p.`ID` SET c.`SampleOrderID` = NULL WHERE c.`SampleOrderID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderassignment` c LEFT JOIN `sampleorderstatus` p ON c.`SampleOrderStatusID` = p.`ID` SET c.`SampleOrderStatusID` = NULL WHERE c.`SampleOrderStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderdetail` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderdetail` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderdetail` c LEFT JOIN `baranglists` p ON c.`BarangListID` = p.`ID` SET c.`BarangListID` = NULL WHERE c.`BarangListID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderdetail` c LEFT JOIN `baranglists` p ON c.`BarangListIDRequest` = p.`ID` SET c.`BarangListIDRequest` = NULL WHERE c.`BarangListIDRequest` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderdetail` c LEFT JOIN `companyprojectdetailcc` p ON c.`ProjectID` = p.`ID` SET c.`ProjectID` = NULL WHERE c.`ProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderdetail` c LEFT JOIN `sampleorderdetailstatus` p ON c.`SampleOrderDetailStatusID` = p.`ID` SET c.`SampleOrderDetailStatusID` = NULL WHERE c.`SampleOrderDetailStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderdetail` c LEFT JOIN `sampleorder` p ON c.`SampleOrderID` = p.`ID` SET c.`SampleOrderID` = NULL WHERE c.`SampleOrderID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderdetail` c LEFT JOIN `satuan` p ON c.`SatuanID` = p.`ID` SET c.`SatuanID` = NULL WHERE c.`SatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderdetail` c LEFT JOIN `suratjalandetails` p ON c.`SuratJalanDetailID` = p.`ID` SET c.`SuratJalanDetailID` = NULL WHERE c.`SuratJalanDetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderdetailassignment` c LEFT JOIN `sampleorderdetail` p ON c.`SampleOrderDetailID` = p.`ID` SET c.`SampleOrderDetailID` = NULL WHERE c.`SampleOrderDetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderdetailassignment` c LEFT JOIN `sampleorderdetailstatus` p ON c.`SampleOrderDetailStatusID` = p.`ID` SET c.`SampleOrderDetailStatusID` = NULL WHERE c.`SampleOrderDetailStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderdetailassignment` c LEFT JOIN `sampleorder` p ON c.`SampleOrderID` = p.`ID` SET c.`SampleOrderID` = NULL WHERE c.`SampleOrderID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderdetailassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `sampleorderlink` c LEFT JOIN `sampleorder` p ON c.`SampleOrderID` = p.`ID` SET c.`SampleOrderID` = NULL WHERE c.`SampleOrderID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimport` c LEFT JOIN `delivery` p ON c.`DeliveryID` = p.`ID` SET c.`DeliveryID` = NULL WHERE c.`DeliveryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimport` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimport` c LEFT JOIN `samplerequestimport` p ON c.`ReferenceSRID` = p.`ID` SET c.`ReferenceSRID` = NULL WHERE c.`ReferenceSRID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimport` c LEFT JOIN `samplerequestimportfrom` p ON c.`RequestFromID` = p.`ID` SET c.`RequestFromID` = NULL WHERE c.`RequestFromID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimport` c LEFT JOIN `samplerequeststatus` p ON c.`SampleRequestStatusID` = p.`ID` SET c.`SampleRequestStatusID` = NULL WHERE c.`SampleRequestStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimport` c LEFT JOIN `urgency` p ON c.`UrgencyID` = p.`ID` SET c.`UrgencyID` = NULL WHERE c.`UrgencyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimport` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportassignment` c LEFT JOIN `samplerequestimport` p ON c.`SampleRequestImportID` = p.`ID` SET c.`SampleRequestImportID` = NULL WHERE c.`SampleRequestImportID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportassignment` c LEFT JOIN `samplerequeststatus` p ON c.`SampleRequestStatusID` = p.`ID` SET c.`SampleRequestStatusID` = NULL WHERE c.`SampleRequestStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportdetail` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportdetail` c LEFT JOIN `baranglists` p ON c.`BaranglistID` = p.`ID` SET c.`BaranglistID` = NULL WHERE c.`BaranglistID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportdetail` c LEFT JOIN `samplerequestimportgoodsreceipt` p ON c.`GoodReceiptDetailID` = p.`ID` SET c.`GoodReceiptDetailID` = NULL WHERE c.`GoodReceiptDetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportdetail` c LEFT JOIN `company` p ON c.`ReqCompanyID` = p.`ID` SET c.`ReqCompanyID` = NULL WHERE c.`ReqCompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportdetail` c LEFT JOIN `samplerequeststatus` p ON c.`SampleRequestDetailStatusID` = p.`ID` SET c.`SampleRequestDetailStatusID` = NULL WHERE c.`SampleRequestDetailStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportdetail` c LEFT JOIN `samplerequestimport` p ON c.`SampleRequestImportID` = p.`ID` SET c.`SampleRequestImportID` = NULL WHERE c.`SampleRequestImportID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportdetail` c LEFT JOIN `satuan` p ON c.`SatuanID` = p.`ID` SET c.`SatuanID` = NULL WHERE c.`SatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportdetailassignment` c LEFT JOIN `samplerequestimportdetail` p ON c.`SampleRequestDetailID` = p.`ID` SET c.`SampleRequestDetailID` = NULL WHERE c.`SampleRequestDetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportdetailassignment` c LEFT JOIN `samplerequeststatus` p ON c.`SampleRequestDetailStatusID` = p.`ID` SET c.`SampleRequestDetailStatusID` = NULL WHERE c.`SampleRequestDetailStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportdetailassignment` c LEFT JOIN `samplerequestimport` p ON c.`SampleRequestImportID` = p.`ID` SET c.`SampleRequestImportID` = NULL WHERE c.`SampleRequestImportID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportdetailassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportgoodsreceipt` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportgoodsreceipt` c LEFT JOIN `baranglists` p ON c.`BarangListsID` = p.`ID` SET c.`BarangListsID` = NULL WHERE c.`BarangListsID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportgoodsreceipt` c LEFT JOIN `samplerequestimportdetail` p ON c.`SampleRequestImportDetailID` = p.`ID` SET c.`SampleRequestImportDetailID` = NULL WHERE c.`SampleRequestImportDetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportgoodsreceipt` c LEFT JOIN `samplerequestimport` p ON c.`SampleRequestImportID` = p.`ID` SET c.`SampleRequestImportID` = NULL WHERE c.`SampleRequestImportID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `samplerequestimportgoodsreceipt` c LEFT JOIN `satuan` p ON c.`SatuanID` = p.`ID` SET c.`SatuanID` = NULL WHERE c.`SatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `specialreference` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `specialreferencehistory` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `specialreferencehistory` c LEFT JOIN `specialreference` p ON c.`SpecialReferenceID` = p.`ID` SET c.`SpecialReferenceID` = NULL WHERE c.`SpecialReferenceID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `specialreferencehistory` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopname` c LEFT JOIN `packing` p ON c.`PackagingID` = p.`ID` SET c.`PackagingID` = NULL WHERE c.`PackagingID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopname` c LEFT JOIN `stockopname_principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopname` c LEFT JOIN `stockopname_product` p ON c.`ProductID` = p.`ID` SET c.`ProductID` = NULL WHERE c.`ProductID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopname` c LEFT JOIN `stockopnameby` p ON c.`StockOpnameBy` = p.`ID` SET c.`StockOpnameBy` = NULL WHERE c.`StockOpnameBy` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopname` c LEFT JOIN `satuan` p ON c.`UOMID` = p.`ID` SET c.`UOMID` = NULL WHERE c.`UOMID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopname` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopname` c LEFT JOIN `warehouse` p ON c.`WarehouseID` = p.`ID` SET c.`WarehouseID` = NULL WHERE c.`WarehouseID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopname_product` c LEFT JOIN `stockopname_principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopname_product` c LEFT JOIN `satuan` p ON c.`UOMID` = p.`ID` SET c.`UOMID` = NULL WHERE c.`UOMID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopnamehistory` c LEFT JOIN `packing` p ON c.`PackagingID` = p.`ID` SET c.`PackagingID` = NULL WHERE c.`PackagingID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopnamehistory` c LEFT JOIN `stockopname_principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopnamehistory` c LEFT JOIN `stockopname_product` p ON c.`ProductID` = p.`ID` SET c.`ProductID` = NULL WHERE c.`ProductID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopnamehistory` c LEFT JOIN `stockopnameby` p ON c.`StockOpnameBy` = p.`ID` SET c.`StockOpnameBy` = NULL WHERE c.`StockOpnameBy` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopnamehistory` c LEFT JOIN `stockopname` p ON c.`StockOpnameID` = p.`ID` SET c.`StockOpnameID` = NULL WHERE c.`StockOpnameID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopnamehistory` c LEFT JOIN `stockopnamestatus` p ON c.`StockOpnameStatusID` = p.`ID` SET c.`StockOpnameStatusID` = NULL WHERE c.`StockOpnameStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopnamehistory` c LEFT JOIN `satuan` p ON c.`UOMID` = p.`ID` SET c.`UOMID` = NULL WHERE c.`UOMID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopnamehistory` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `stockopnamehistory` c LEFT JOIN `warehouse` p ON c.`WarehouseID` = p.`ID` SET c.`WarehouseID` = NULL WHERE c.`WarehouseID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `successstory` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `successstory` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `successstory` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `successstory` c LEFT JOIN `groupdivision` p ON c.`GroupDivisionID` = p.`ID` SET c.`GroupDivisionID` = NULL WHERE c.`GroupDivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `successstory` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `successstory` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `successstory` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `successstoryassignment` c LEFT JOIN `successstory` p ON c.`SuccessStoryID` = p.`ID` SET c.`SuccessStoryID` = NULL WHERE c.`SuccessStoryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `successstoryassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `suratjalan` c LEFT JOIN `companycp` p ON c.`CompanyCPID` = p.`ID` SET c.`CompanyCPID` = NULL WHERE c.`CompanyCPID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `suratjalan` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `suratjalan` c LEFT JOIN `delivery` p ON c.`DeliveryID` = p.`ID` SET c.`DeliveryID` = NULL WHERE c.`DeliveryID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `suratjalan` c LEFT JOIN `location` p ON c.`LocationID` = p.`ID` SET c.`LocationID` = NULL WHERE c.`LocationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `suratjalan` c LEFT JOIN `sampleorder` p ON c.`SampleOrderID` = p.`ID` SET c.`SampleOrderID` = NULL WHERE c.`SampleOrderID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `suratjalan` c LEFT JOIN `users` p ON c.`UserIDCreatorSJ` = p.`ID` SET c.`UserIDCreatorSJ` = NULL WHERE c.`UserIDCreatorSJ` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `suratjalan` c LEFT JOIN `users` p ON c.`UserIDsales` = p.`ID` SET c.`UserIDsales` = NULL WHERE c.`UserIDsales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `suratjalandetails` c LEFT JOIN `application` p ON c.`ApplicationID` = p.`ID` SET c.`ApplicationID` = NULL WHERE c.`ApplicationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `suratjalandetails` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `suratjalandetails` c LEFT JOIN `baranglists` p ON c.`BarangListID` = p.`ID` SET c.`BarangListID` = NULL WHERE c.`BarangListID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `suratjalandetails` c LEFT JOIN `sampleorder` p ON c.`SampleOrderID` = p.`ID` SET c.`SampleOrderID` = NULL WHERE c.`SampleOrderID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `suratjalandetails` c LEFT JOIN `satuan` p ON c.`SatuanID` = p.`ID` SET c.`SatuanID` = NULL WHERE c.`SatuanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `suratjalandetails` c LEFT JOIN `suratjalan` p ON c.`SuratJalanID` = p.`ID` SET c.`SuratJalanID` = NULL WHERE c.`SuratJalanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userbusinesstravelbranch` c LEFT JOIN `branch` p ON c.`BranchID` = p.`ID` SET c.`BranchID` = NULL WHERE c.`BranchID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userbusinesstravelbranch` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userdetails` c LEFT JOIN `branch` p ON c.`BranchID` = p.`ID` SET c.`BranchID` = NULL WHERE c.`BranchID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userdetails` c LEFT JOIN `department` p ON c.`DepartmentID` = p.`ID` SET c.`DepartmentID` = NULL WHERE c.`DepartmentID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userdetails` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userdivision` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userdivision` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `usereducation` c LEFT JOIN `education` p ON c.`EducationID` = p.`ID` SET c.`EducationID` = NULL WHERE c.`EducationID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `usereducation` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userjob` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userlabgroupdivision` c LEFT JOIN `groupdivision` p ON c.`GroupDivisionID` = p.`ID` SET c.`GroupDivisionID` = NULL WHERE c.`GroupDivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userlabgroupdivision` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userprincipal` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userprincipal` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `users` c LEFT JOIN `branch` p ON c.`BranchID` = p.`ID` SET c.`BranchID` = NULL WHERE c.`BranchID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `users` c LEFT JOIN `department` p ON c.`DepartmentID` = p.`ID` SET c.`DepartmentID` = NULL WHERE c.`DepartmentID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `users` c LEFT JOIN `users` p ON c.`HeadID` = p.`ID` SET c.`HeadID` = NULL WHERE c.`HeadID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `users` c LEFT JOIN `maritalstatus` p ON c.`MaritalStatusID` = p.`ID` SET c.`MaritalStatusID` = NULL WHERE c.`MaritalStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `users` c LEFT JOIN `role` p ON c.`RoleID` = p.`ID` SET c.`RoleID` = NULL WHERE c.`RoleID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `usersperiode` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userwarehouse` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `userwarehouse` c LEFT JOIN `warehouse` p ON c.`WarehouseID` = p.`ID` SET c.`WarehouseID` = NULL WHERE c.`WarehouseID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicle` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicle` c LEFT JOIN `users` p ON c.`UserIDOwner` = p.`ID` SET c.`UserIDOwner` = NULL WHERE c.`UserIDOwner` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicle` c LEFT JOIN `vehiclebrand` p ON c.`VehicleBrandID` = p.`ID` SET c.`VehicleBrandID` = NULL WHERE c.`VehicleBrandID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicle` c LEFT JOIN `vehiclebrandtype` p ON c.`VehicleBrandTypeID` = p.`ID` SET c.`VehicleBrandTypeID` = NULL WHERE c.`VehicleBrandTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicle` c LEFT JOIN `vehiclecolor` p ON c.`VehicleColorID` = p.`ID` SET c.`VehicleColorID` = NULL WHERE c.`VehicleColorID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicle` c LEFT JOIN `vehiclefueltype` p ON c.`VehicleFuelTypeID` = p.`ID` SET c.`VehicleFuelTypeID` = NULL WHERE c.`VehicleFuelTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicle` c LEFT JOIN `vehicletype` p ON c.`VehicleTypeID` = p.`ID` SET c.`VehicleTypeID` = NULL WHERE c.`VehicleTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `users` p ON c.`UserIDOwnerAfter` = p.`ID` SET c.`UserIDOwnerAfter` = NULL WHERE c.`UserIDOwnerAfter` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `users` p ON c.`UserIDOwnerBefore` = p.`ID` SET c.`UserIDOwnerBefore` = NULL WHERE c.`UserIDOwnerBefore` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `vehiclebrand` p ON c.`VehicleBrandIDAfter` = p.`ID` SET c.`VehicleBrandIDAfter` = NULL WHERE c.`VehicleBrandIDAfter` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `vehiclebrand` p ON c.`VehicleBrandIDBefore` = p.`ID` SET c.`VehicleBrandIDBefore` = NULL WHERE c.`VehicleBrandIDBefore` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `vehiclebrandtype` p ON c.`VehicleBrandTypeIDAfter` = p.`ID` SET c.`VehicleBrandTypeIDAfter` = NULL WHERE c.`VehicleBrandTypeIDAfter` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `vehiclebrandtype` p ON c.`VehicleBrandTypeIDBefore` = p.`ID` SET c.`VehicleBrandTypeIDBefore` = NULL WHERE c.`VehicleBrandTypeIDBefore` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `vehiclecolor` p ON c.`VehicleColorIDAfter` = p.`ID` SET c.`VehicleColorIDAfter` = NULL WHERE c.`VehicleColorIDAfter` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `vehiclecolor` p ON c.`VehicleColorIDBefore` = p.`ID` SET c.`VehicleColorIDBefore` = NULL WHERE c.`VehicleColorIDBefore` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `vehiclefueltype` p ON c.`VehicleFuelTypeIDAfter` = p.`ID` SET c.`VehicleFuelTypeIDAfter` = NULL WHERE c.`VehicleFuelTypeIDAfter` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `vehiclefueltype` p ON c.`VehicleFuelTypeIDBefore` = p.`ID` SET c.`VehicleFuelTypeIDBefore` = NULL WHERE c.`VehicleFuelTypeIDBefore` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `vehicle` p ON c.`VehicleID` = p.`ID` SET c.`VehicleID` = NULL WHERE c.`VehicleID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `vehiclestatus` p ON c.`VehicleStatusID` = p.`ID` SET c.`VehicleStatusID` = NULL WHERE c.`VehicleStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `vehicletype` p ON c.`VehicleTypeIDAfter` = p.`ID` SET c.`VehicleTypeIDAfter` = NULL WHERE c.`VehicleTypeIDAfter` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleassignment` c LEFT JOIN `vehicletype` p ON c.`VehicleTypeIDBefore` = p.`ID` SET c.`VehicleTypeIDBefore` = NULL WHERE c.`VehicleTypeIDBefore` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehiclebrandtype` c LEFT JOIN `vehiclebrand` p ON c.`VehicleBrandID` = p.`ID` SET c.`VehicleBrandID` = NULL WHERE c.`VehicleBrandID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequest` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequest` c LEFT JOIN `users` p ON c.`UserIDOwner` = p.`ID` SET c.`UserIDOwner` = NULL WHERE c.`UserIDOwner` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequest` c LEFT JOIN `vehicle` p ON c.`VehicleID` = p.`ID` SET c.`VehicleID` = NULL WHERE c.`VehicleID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequest` c LEFT JOIN `vehicleservicerequeststatus` p ON c.`VehicleServiceRequestStatusID` = p.`ID` SET c.`VehicleServiceRequestStatusID` = NULL WHERE c.`VehicleServiceRequestStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequestassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequestassignment` c LEFT JOIN `vehicleservicerequest` p ON c.`VehicleServiceRequestID` = p.`ID` SET c.`VehicleServiceRequestID` = NULL WHERE c.`VehicleServiceRequestID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequestassignment` c LEFT JOIN `vehicleservicerequeststatus` p ON c.`VehicleServiceRequestStatusID` = p.`ID` SET c.`VehicleServiceRequestStatusID` = NULL WHERE c.`VehicleServiceRequestStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequestdetails` c LEFT JOIN `vehicleservicerequeststatus` p ON c.`VehicleServiceRequestDetailStatus` = p.`ID` SET c.`VehicleServiceRequestDetailStatus` = NULL WHERE c.`VehicleServiceRequestDetailStatus` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequestdetails` c LEFT JOIN `vehicleservicerequest` p ON c.`VehicleServiceRequestID` = p.`ID` SET c.`VehicleServiceRequestID` = NULL WHERE c.`VehicleServiceRequestID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequestdetails` c LEFT JOIN `vehicleservicetype` p ON c.`VehicleServiceTypeID` = p.`ID` SET c.`VehicleServiceTypeID` = NULL WHERE c.`VehicleServiceTypeID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequestdetailsassigntment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequestdetailsassigntment` c LEFT JOIN `vehicleservicerequestdetails` p ON c.`VehicleServiceRequestDetailID` = p.`ID` SET c.`VehicleServiceRequestDetailID` = NULL WHERE c.`VehicleServiceRequestDetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequestdetailsassigntment` c LEFT JOIN `vehicleservicerequest` p ON c.`VehicleServiceRequestID` = p.`ID` SET c.`VehicleServiceRequestID` = NULL WHERE c.`VehicleServiceRequestID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `vehicleservicerequestdetailsassigntment` c LEFT JOIN `vehicleservicerequeststatus` p ON c.`VehicleServiceRequestStatusID` = p.`ID` SET c.`VehicleServiceRequestStatusID` = NULL WHERE c.`VehicleServiceRequestStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplan` c LEFT JOIN `companycp` p ON c.`CompanyCPID` = p.`ID` SET c.`CompanyCPID` = NULL WHERE c.`CompanyCPID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplan` c LEFT JOIN `company` p ON c.`CompanyID` = p.`ID` SET c.`CompanyID` = NULL WHERE c.`CompanyID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplan` c LEFT JOIN `division` p ON c.`DivisionID` = p.`ID` SET c.`DivisionID` = NULL WHERE c.`DivisionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplan` c LEFT JOIN `companyproject` p ON c.`ProjectID` = p.`ID` SET c.`ProjectID` = NULL WHERE c.`ProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplan` c LEFT JOIN `users` p ON c.`UserIDInput` = p.`ID` SET c.`UserIDInput` = NULL WHERE c.`UserIDInput` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplan` c LEFT JOIN `users` p ON c.`UserIDSales` = p.`ID` SET c.`UserIDSales` = NULL WHERE c.`UserIDSales` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplan` c LEFT JOIN `users` p ON c.`UserIDVisitWith` = p.`ID` SET c.`UserIDVisitWith` = NULL WHERE c.`UserIDVisitWith` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplan` c LEFT JOIN `visitplanstatus` p ON c.`VisitPlanStatusID` = p.`ID` SET c.`VisitPlanStatusID` = NULL WHERE c.`VisitPlanStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplan` c LEFT JOIN `principalcp` p ON c.`VisitPrincipalCPID` = p.`ID` SET c.`VisitPrincipalCPID` = NULL WHERE c.`VisitPrincipalCPID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplan` c LEFT JOIN `principal` p ON c.`VisitingPrincipalID` = p.`ID` SET c.`VisitingPrincipalID` = NULL WHERE c.`VisitingPrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplanassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplanassignment` c LEFT JOIN `visitplan` p ON c.`VisitPlanID` = p.`ID` SET c.`VisitPlanID` = NULL WHERE c.`VisitPlanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplanassignment` c LEFT JOIN `visitplanstatus` p ON c.`VisitPlanStatusID` = p.`ID` SET c.`VisitPlanStatusID` = NULL WHERE c.`VisitPlanStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplancompanycpdetail` c LEFT JOIN `companycp` p ON c.`CompanyCPID` = p.`ID` SET c.`CompanyCPID` = NULL WHERE c.`CompanyCPID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplancompanycpdetail` c LEFT JOIN `visitplan` p ON c.`VisitPlanID` = p.`ID` SET c.`VisitPlanID` = NULL WHERE c.`VisitPlanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplandetail` c LEFT JOIN `action` p ON c.`ActionID` = p.`ID` SET c.`ActionID` = NULL WHERE c.`ActionID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplandetail` c LEFT JOIN `barang` p ON c.`BarangID` = p.`ID` SET c.`BarangID` = NULL WHERE c.`BarangID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplandetail` c LEFT JOIN `principal` p ON c.`PrincipalID` = p.`ID` SET c.`PrincipalID` = NULL WHERE c.`PrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplandetail` c LEFT JOIN `companyprojectdetailcc` p ON c.`ProjectID` = p.`ID` SET c.`ProjectID` = NULL WHERE c.`ProjectID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplandetail` c LEFT JOIN `visitplanstatus` p ON c.`VisitActionStatusID` = p.`ID` SET c.`VisitActionStatusID` = NULL WHERE c.`VisitActionStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplandetail` c LEFT JOIN `visitplan` p ON c.`VisitPlanID` = p.`ID` SET c.`VisitPlanID` = NULL WHERE c.`VisitPlanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplandetailassignment` c LEFT JOIN `users` p ON c.`UserID` = p.`ID` SET c.`UserID` = NULL WHERE c.`UserID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplandetailassignment` c LEFT JOIN `visitplanstatus` p ON c.`VisitActionStatusID` = p.`ID` SET c.`VisitActionStatusID` = NULL WHERE c.`VisitActionStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplandetailassignment` c LEFT JOIN `visitplandetail` p ON c.`VisitPlanDetailID` = p.`ID` SET c.`VisitPlanDetailID` = NULL WHERE c.`VisitPlanDetailID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplandetailassignment` c LEFT JOIN `visitplan` p ON c.`VisitPlanID` = p.`ID` SET c.`VisitPlanID` = NULL WHERE c.`VisitPlanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplandetailassignment` c LEFT JOIN `visitplanstatus` p ON c.`VisitPlanStatusID` = p.`ID` SET c.`VisitPlanStatusID` = NULL WHERE c.`VisitPlanStatusID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplanfrienddetail` c LEFT JOIN `users` p ON c.`UserIDVisitWith` = p.`ID` SET c.`UserIDVisitWith` = NULL WHERE c.`UserIDVisitWith` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplanfrienddetail` c LEFT JOIN `visitplan` p ON c.`VisitPlanID` = p.`ID` SET c.`VisitPlanID` = NULL WHERE c.`VisitPlanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplanlink` c LEFT JOIN `visitplan` p ON c.`VisitPlanID` = p.`ID` SET c.`VisitPlanID` = NULL WHERE c.`VisitPlanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplanprincipalvisitdetail` c LEFT JOIN `visitplan` p ON c.`VisitPlanID` = p.`ID` SET c.`VisitPlanID` = NULL WHERE c.`VisitPlanID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplanprincipalvisitdetail` c LEFT JOIN `principalcp` p ON c.`VisitingPrincipalCPID` = p.`ID` SET c.`VisitingPrincipalCPID` = NULL WHERE c.`VisitingPrincipalCPID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `visitplanprincipalvisitdetail` c LEFT JOIN `principal` p ON c.`VisitingPrincipalID` = p.`ID` SET c.`VisitingPrincipalID` = NULL WHERE c.`VisitingPrincipalID` IS NOT NULL AND p.`ID` IS NULL;
UPDATE `warehouse` c LEFT JOIN `warehouse` p ON c.`ParentID` = p.`ID` SET c.`ParentID` = NULL WHERE c.`ParentID` IS NOT NULL AND p.`ID` IS NULL;


COMMIT;
-- lock_wait_timeout and innodb_lock_wait_timeout are DELIBERATELY NOT restored here.
-- Sections 7 and 8 are the ones that take metadata locks; they need the guard more than
-- sections 5-6 did. Both are restored at the very end of the file.

-- ---------------------------------------------------------------------
-- SECTION 7 - Supporting indexes (636 added, 1 replaced)
-- InnoDB requires an index on the child column of every foreign key; most of these back
-- section 8. They must exist before it runs.
-- ---------------------------------------------------------------------
ALTER TABLE `application` ADD INDEX `application_DivisionID` (`DivisionID`);
ALTER TABLE `application` ADD INDEX `GroupDivisionID` (`GroupDivisionID`,`DivisionID`);
ALTER TABLE `bank` ADD INDEX `bank_QuotationPriceDescID` (`QuotationPriceDescID`);
ALTER TABLE `bankdivision` ADD INDEX `bankdivision_BankID` (`BankID`);
ALTER TABLE `bankdivision` ADD INDEX `DivisionID` (`DivisionID`);
ALTER TABLE `bankdivision` ADD INDEX `DivisionID_2` (`DivisionID`,`BankID`);
ALTER TABLE `barang` ADD INDEX `barang_PrincipalID` (`PrincipalID`);
ALTER TABLE `barang` ADD INDEX `barang_SatuanID` (`SatuanID`);
ALTER TABLE `barang` ADD INDEX `barang_TypeID` (`TypeID`);
ALTER TABLE `barang` ADD INDEX `CategoryID` (`CategoryID`,`PrincipalID`);
ALTER TABLE `baranglist` ADD INDEX `baranglist_BarangID` (`BarangID`);
ALTER TABLE `baranglist` ADD INDEX `baranglist_SampleOrderDetailID` (`SampleOrderDetailID`);
ALTER TABLE `baranglist` ADD INDEX `baranglist_SatuanID` (`SatuanID`);
ALTER TABLE `baranglist` ADD INDEX `BarangListStatusID` (`BarangListStatusID`,`BarangID`,`SatuanID`,`SampleOrderDetailID`);
ALTER TABLE `baranglists` ADD INDEX `BarangID` (`BarangID`,`SatuanID`);
ALTER TABLE `baranglists` ADD INDEX `baranglists_SatuanID` (`SatuanID`);
ALTER TABLE `barangstockmin` ADD INDEX `BarangID` (`BarangID`,`SatuanID`);
ALTER TABLE `barangstockmin` ADD INDEX `barangstockmin_SatuanID` (`SatuanID`);
ALTER TABLE `budgetandtarget` ADD INDEX `budgetandtarget_BudgetAndTargetPeriodeID` (`BudgetAndTargetPeriodeID`);
ALTER TABLE `budgetandtarget` ADD INDEX `budgetandtarget_CompanyID` (`CompanyID`);
ALTER TABLE `budgetandtarget` ADD INDEX `budgetandtarget_DivisionID` (`DivisionID`);
ALTER TABLE `budgetandtarget` ADD INDEX `budgetandtarget_UserIDInput` (`UserIDInput`);
ALTER TABLE `budgetandtarget` ADD INDEX `budgetandtarget_UserIDSales` (`UserIDSales`);
ALTER TABLE `budgetandtargetassignment` ADD INDEX `budgetandtargetassignment_BudgetAndTargetStatusID` (`BudgetAndTargetStatusID`);
ALTER TABLE `budgetandtargetassignment` ADD INDEX `budgetandtargetassignment_UserID` (`UserID`);
ALTER TABLE `comissionpercentage` ADD INDEX `comissionpercentage_PrincipalID` (`PrincipalID`);
ALTER TABLE `company` ADD INDEX `company_BranchID` (`BranchID`);
ALTER TABLE `company` ADD INDEX `company_CompanyCategoryID` (`CompanyCategoryID`);
ALTER TABLE `company` ADD INDEX `company_DivisionID` (`DivisionID`);
ALTER TABLE `company` ADD INDEX `company_UserIDSales` (`UserIDSales`);
ALTER TABLE `company` ADD INDEX `IndustryID` (`IndustryID`,`UserIDSales`);
ALTER TABLE `companyaccessothers` ADD INDEX `companyaccessothers_CompanyID` (`CompanyID`);
ALTER TABLE `companyaccessothers` ADD INDEX `UserID` (`UserID`,`CompanyID`);
ALTER TABLE `companycategory` ADD INDEX `companycategory_GroupDivID` (`GroupDivID`);
ALTER TABLE `companycategorylist` ADD INDEX `companycategorylist_CompanyCategoryID` (`CompanyCategoryID`);
ALTER TABLE `companycategorylist` ADD INDEX `companycategorylist_CompanyID` (`CompanyID`);
ALTER TABLE `companycp` ADD INDEX `companycp_AddressType` (`AddressType`);
ALTER TABLE `companycp` ADD INDEX `CompanyID` (`CompanyID`);
ALTER TABLE `companycpassignment` ADD INDEX `companycpassignment_AddressType` (`AddressType`);
ALTER TABLE `companycpassignment` ADD INDEX `companycpassignment_CompanyCPID` (`CompanyCPID`);
ALTER TABLE `companycpassignment` ADD INDEX `companycpassignment_CompanyID` (`CompanyID`);
ALTER TABLE `companycpassignment` ADD INDEX `UsersID` (`UsersID`,`CompanyCPID`,`CompanyID`);
ALTER TABLE `companyhistory` ADD INDEX `companyhistory_BranchID` (`BranchID`);
ALTER TABLE `companyhistory` ADD INDEX `companyhistory_CompanyID` (`CompanyID`);
ALTER TABLE `companyhistory` ADD INDEX `companyhistory_DivisionID` (`DivisionID`);
ALTER TABLE `companyhistory` ADD INDEX `companyhistory_UserIDSales` (`UserIDSales`);
ALTER TABLE `companyhistory` ADD INDEX `UserID` (`UserID`,`CompanyID`,`IndustryID`,`UserIDSales`);
ALTER TABLE `companyindustry` ADD INDEX `companyindustry_CompanyID` (`CompanyID`);
ALTER TABLE `companyindustry` ADD INDEX `companyindustry_IndustryID` (`IndustryID`);
ALTER TABLE `companyproduct` ADD INDEX `CompanyID` (`CompanyID`,`DivisionID`,`ApplicationID`,`CCPrincipalID`,`CCBarangID`,`CCVolumeSatuanID`,`CCPriceSatuanID`,`CompetitorPrincipalID`,`CompetitorBarangID`,`CompetitorVolumeSatuanID`,`CompetitorPriceSatuanID`);
ALTER TABLE `companyproduct` ADD INDEX `companyproduct_ApplicationID` (`ApplicationID`);
ALTER TABLE `companyproduct` ADD INDEX `companyproduct_CCBarangID` (`CCBarangID`);
ALTER TABLE `companyproduct` ADD INDEX `companyproduct_CCPriceSatuanID` (`CCPriceSatuanID`);
ALTER TABLE `companyproduct` ADD INDEX `companyproduct_CCPrincipalID` (`CCPrincipalID`);
ALTER TABLE `companyproduct` ADD INDEX `companyproduct_CCVolumeSatuanID` (`CCVolumeSatuanID`);
ALTER TABLE `companyproduct` ADD INDEX `companyproduct_CompetitorBarangID` (`CompetitorBarangID`);
ALTER TABLE `companyproduct` ADD INDEX `companyproduct_CompetitorPriceSatuanID` (`CompetitorPriceSatuanID`);
ALTER TABLE `companyproduct` ADD INDEX `companyproduct_CompetitorPrincipalID` (`CompetitorPrincipalID`);
ALTER TABLE `companyproduct` ADD INDEX `companyproduct_CompetitorVolumeSatuanID` (`CompetitorVolumeSatuanID`);
ALTER TABLE `companyproduct` ADD INDEX `companyproduct_DivisionID` (`DivisionID`);
ALTER TABLE `companyproductapplication` ADD INDEX `companyproductapplication_CompanyID` (`CompanyID`);
ALTER TABLE `companyproductapplication` ADD INDEX `companyproductapplication_ProductApplicationID` (`ProductApplicationID`);
ALTER TABLE `companyproductassignment` ADD INDEX `companyproductassignment_ApplicationID` (`ApplicationID`);
ALTER TABLE `companyproductassignment` ADD INDEX `companyproductassignment_CCBarangID` (`CCBarangID`);
ALTER TABLE `companyproductassignment` ADD INDEX `companyproductassignment_CCPriceSatuanID` (`CCPriceSatuanID`);
ALTER TABLE `companyproductassignment` ADD INDEX `companyproductassignment_CCPrincipalID` (`CCPrincipalID`);
ALTER TABLE `companyproductassignment` ADD INDEX `companyproductassignment_CCVolumeSatuanID` (`CCVolumeSatuanID`);
ALTER TABLE `companyproductassignment` ADD INDEX `companyproductassignment_CompanyID` (`CompanyID`);
ALTER TABLE `companyproductassignment` ADD INDEX `companyproductassignment_CompanyProductID` (`CompanyProductID`);
ALTER TABLE `companyproductassignment` ADD INDEX `companyproductassignment_CompetitorBarangID` (`CompetitorBarangID`);
ALTER TABLE `companyproductassignment` ADD INDEX `companyproductassignment_CompetitorPriceSatuanID` (`CompetitorPriceSatuanID`);
ALTER TABLE `companyproductassignment` ADD INDEX `companyproductassignment_CompetitorPrincipalID` (`CompetitorPrincipalID`);
ALTER TABLE `companyproductassignment` ADD INDEX `companyproductassignment_CompetitorVolumeSatuanID` (`CompetitorVolumeSatuanID`);
ALTER TABLE `companyproductassignment` ADD INDEX `companyproductassignment_DivisionID` (`DivisionID`);
ALTER TABLE `companyproductassignment` ADD INDEX `UsersID` (`UsersID`,`CompanyProductID`,`CompanyID`,`DivisionID`,`ApplicationID`,`CCPrincipalID`,`CCBarangID`,`CCVolumeSatuanID`,`CCPriceSatuanID`,`CompetitorPrincipalID`,`CompetitorBarangID`,`CompetitorVolumeSatuanID`,`CompetitorPriceSatuanID`);
ALTER TABLE `companyproductcategory` ADD INDEX `companyproductcategory_CompanyID` (`CompanyID`);
ALTER TABLE `companyproductcategory` ADD INDEX `companyproductcategory_ProductCategoryID` (`ProductCategoryID`);
ALTER TABLE `companyproduction` ADD INDEX `CompanyID` (`CompanyID`,`DivisionID`,`ApplicationID`,`VolumeSatuanID`);
ALTER TABLE `companyproduction` ADD INDEX `companyproduction_ApplicationID` (`ApplicationID`);
ALTER TABLE `companyproduction` ADD INDEX `companyproduction_DivisionID` (`DivisionID`);
ALTER TABLE `companyproduction` ADD INDEX `companyproduction_VolumeSatuanID` (`VolumeSatuanID`);
ALTER TABLE `companyproductionassignment` ADD INDEX `companyproductionassignment_ApplicationID` (`ApplicationID`);
ALTER TABLE `companyproductionassignment` ADD INDEX `companyproductionassignment_CompanyID` (`CompanyID`);
ALTER TABLE `companyproductionassignment` ADD INDEX `companyproductionassignment_CompanyProductionID` (`CompanyProductionID`);
ALTER TABLE `companyproductionassignment` ADD INDEX `companyproductionassignment_DivisionID` (`DivisionID`);
ALTER TABLE `companyproductionassignment` ADD INDEX `companyproductionassignment_VolumeSatuanID` (`VolumeSatuanID`);
ALTER TABLE `companyproductionassignment` ADD INDEX `UsersID` (`UsersID`,`CompanyProductionID`,`CompanyID`,`DivisionID`,`ApplicationID`,`VolumeSatuanID`);
ALTER TABLE `companyproject` ADD INDEX `companyproject_CompanyCP` (`CompanyCP`);
ALTER TABLE `companyproject` ADD INDEX `companyproject_CompanyID` (`CompanyID`);
ALTER TABLE `companyproject` ADD INDEX `companyproject_DivisionID` (`DivisionID`);
ALTER TABLE `companyproject` ADD INDEX `companyproject_IndustryID` (`IndustryID`);
ALTER TABLE `companyproject` ADD INDEX `companyproject_ProjectID` (`ProjectID`);
ALTER TABLE `companyproject` ADD INDEX `companyproject_ProjectPriority` (`ProjectPriority`);
ALTER TABLE `companyproject` ADD INDEX `companyproject_ProjectStatusID` (`ProjectStatusID`);
ALTER TABLE `companyproject` ADD INDEX `companyproject_UserIDInput` (`UserIDInput`);
ALTER TABLE `companyproject` ADD INDEX `companyproject_UserIDSales` (`UserIDSales`);
ALTER TABLE `companyprojectassignment` ADD INDEX `companyprojectassignment_CompanyProjectDetailCCID` (`CompanyProjectDetailCCID`);
ALTER TABLE `companyprojectassignment` ADD INDEX `companyprojectassignment_CompanyProjectDetailID` (`CompanyProjectDetailID`);
ALTER TABLE `companyprojectassignment` ADD INDEX `companyprojectassignment_CompanyProjectID` (`CompanyProjectID`);
ALTER TABLE `companyprojectassignment` ADD INDEX `companyprojectassignment_ProjectStatusID` (`ProjectStatusID`);
ALTER TABLE `companyprojectassignment` ADD INDEX `companyprojectassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `companyprojectdetailcc` ADD INDEX `companyprojectdetailcc_CompanyProjectID` (`CompanyProjectID`);
ALTER TABLE `companyprojectdetailcc` ADD INDEX `companyprojectdetailcc_DetailID` (`DetailID`);
ALTER TABLE `companyprojectdetailcc` ADD INDEX `companyprojectdetailcc_ItemReasonID` (`ItemReasonID`);
ALTER TABLE `companyprojectdetailcc` ADD INDEX `companyprojectdetailcc_ItemStatusID` (`ItemStatusID`);
ALTER TABLE `companyprojectdetailcc` ADD INDEX `companyprojectdetailcc_PriceTypeID` (`PriceTypeID`);
ALTER TABLE `companyprojectdetailcc` ADD INDEX `companyprojectdetailcc_PrincipalID` (`PrincipalID`);
ALTER TABLE `companyprojectdetailcc` ADD INDEX `companyprojectdetailcc_ProductID` (`ProductID`);
ALTER TABLE `companyprojectdetailcc` ADD INDEX `companyprojectdetailcc_ProjectStatusID` (`ProjectStatusID`);
ALTER TABLE `companyprojectdetailcc` ADD INDEX `companyprojectdetailcc_QtTypeID` (`QtTypeID`);
ALTER TABLE `companyprojectdetailcc` ADD INDEX `companyprojectdetailcc_SatuanID` (`SatuanID`);
ALTER TABLE `companyprojectdetailccassignment` ADD INDEX `companyprojectdetailccassignment_CompanyProjectID` (`CompanyProjectID`);
ALTER TABLE `companyprojectdetailccassignment` ADD INDEX `companyprojectdetailccassignment_DetailCCID` (`DetailCCID`);
ALTER TABLE `companyprojectdetailccassignment` ADD INDEX `companyprojectdetailccassignment_DetailID` (`DetailID`);
ALTER TABLE `companyprojectdetailccassignment` ADD INDEX `companyprojectdetailccassignment_PriceTypeID` (`PriceTypeID`);
ALTER TABLE `companyprojectdetailccassignment` ADD INDEX `companyprojectdetailccassignment_PrincipalID` (`PrincipalID`);
ALTER TABLE `companyprojectdetailccassignment` ADD INDEX `companyprojectdetailccassignment_ProductID` (`ProductID`);
ALTER TABLE `companyprojectdetailccassignment` ADD INDEX `companyprojectdetailccassignment_QtTypeID` (`QtTypeID`);
ALTER TABLE `companyprojectdetailccassignment` ADD INDEX `companyprojectdetailccassignment_SatuanID` (`SatuanID`);
ALTER TABLE `companyprojectdetailccassignment` ADD INDEX `companyprojectdetailccassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `companyprojectdetailcomp` ADD INDEX `companyprojectdetailcomp_CompanyProjectID` (`CompanyProjectID`);
ALTER TABLE `companyprojectdetailcomp` ADD INDEX `companyprojectdetailcomp_DetailID` (`DetailID`);
ALTER TABLE `companyprojectdetailcomp` ADD INDEX `companyprojectdetailcomp_PriceTypeIDComp` (`PriceTypeIDComp`);
ALTER TABLE `companyprojectdetailcomp` ADD INDEX `companyprojectdetailcomp_PrincipalIDComp` (`PrincipalIDComp`);
ALTER TABLE `companyprojectdetailcomp` ADD INDEX `companyprojectdetailcomp_ProductIDComp` (`ProductIDComp`);
ALTER TABLE `companyprojectdetailcomp` ADD INDEX `companyprojectdetailcomp_QtTypeIDComp` (`QtTypeIDComp`);
ALTER TABLE `companyprojectdetailcomp` ADD INDEX `companyprojectdetailcomp_SatuanIDComp` (`SatuanIDComp`);
ALTER TABLE `companyprojectdetailcompassignment` ADD INDEX `companyprojectdetailcompassignment_CompanyProjectIDID` (`CompanyProjectID`);
ALTER TABLE `companyprojectdetailcompassignment` ADD INDEX `companyprojectdetailcompassignment_DetailCompID` (`DetailCompID`);
ALTER TABLE `companyprojectdetailcompassignment` ADD INDEX `companyprojectdetailcompassignment_DetailID` (`DetailID`);
ALTER TABLE `companyprojectdetailcompassignment` ADD INDEX `companyprojectdetailcompassignment_PriceTypeIDComp` (`PriceTypeIDComp`);
ALTER TABLE `companyprojectdetailcompassignment` ADD INDEX `companyprojectdetailcompassignment_PrincipalIDComp` (`PrincipalIDComp`);
ALTER TABLE `companyprojectdetailcompassignment` ADD INDEX `companyprojectdetailcompassignment_ProductIDComp` (`ProductIDComp`);
ALTER TABLE `companyprojectdetailcompassignment` ADD INDEX `companyprojectdetailcompassignment_QtTypeIDComp` (`QtTypeIDComp`);
ALTER TABLE `companyprojectdetailcompassignment` ADD INDEX `companyprojectdetailcompassignment_SatuanIDComp` (`SatuanIDComp`);
ALTER TABLE `companyprojectdetailcompassignment` ADD INDEX `companyprojectdetailcompassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `companyprojectdetails` ADD INDEX `companyprojectdetails_ApplicationID` (`ApplicationID`);
ALTER TABLE `companyprojectdetails` ADD INDEX `companyprojectdetails_CompanyProjectID` (`CompanyProjectID`);
ALTER TABLE `companyprojectdetails` ADD INDEX `companyprojectdetails_OpportunityGroupID` (`OpportunityGroupID`);
ALTER TABLE `companyprojectdetails` ADD INDEX `companyprojectdetails_ProjectStatusID` (`ProjectStatusID`);
ALTER TABLE `companyprojectdetailsassignment` ADD INDEX `companyprojectdetailsassignment_ApplicationID` (`ApplicationID`);
ALTER TABLE `companyprojectdetailsassignment` ADD INDEX `companyprojectdetailsassignment_CompanyProjectID` (`CompanyProjectID`);
ALTER TABLE `companyprojectdetailsassignment` ADD INDEX `companyprojectdetailsassignment_DetailID` (`DetailID`);
ALTER TABLE `companyprojectdetailsassignment` ADD INDEX `companyprojectdetailsassignment_OpportunityGroupID` (`OpportunityGroupID`);
ALTER TABLE `companyprojectdetailsassignment` ADD INDEX `companyprojectdetailsassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `companyprojectdetailstatusassignment` ADD INDEX `companyprojectdetailstatusassignment_CompanyProjectID` (`CompanyProjectID`);
ALTER TABLE `companyprojectdetailstatusassignment` ADD INDEX `companyprojectdetailstatusassignment_DetailCCID` (`DetailCCID`);
ALTER TABLE `companyprojectdetailstatusassignment` ADD INDEX `companyprojectdetailstatusassignment_DetailID` (`DetailID`);
ALTER TABLE `companyprojectdetailstatusassignment` ADD INDEX `companyprojectdetailstatusassignment_ItemReasonID` (`ItemReasonID`);
ALTER TABLE `companyprojectdetailstatusassignment` ADD INDEX `companyprojectdetailstatusassignment_ItemStatusID` (`ItemStatusID`);
ALTER TABLE `companyprojectdetailstatusassignment` ADD INDEX `companyprojectdetailstatusassignment_ProjectStatusID` (`ProjectStatusID`);
ALTER TABLE `companyprojectdetailstatusassignment` ADD INDEX `companyprojectdetailstatusassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `companyprojectdetailstatusreason` ADD INDEX `companyprojectdetailstatusreason_StatusID` (`StatusID`);
ALTER TABLE `companyprojectheaderassignment` ADD INDEX `companyprojectheaderassignment_CompanyCP` (`CompanyCP`);
ALTER TABLE `companyprojectheaderassignment` ADD INDEX `companyprojectheaderassignment_CompanyID` (`CompanyID`);
ALTER TABLE `companyprojectheaderassignment` ADD INDEX `companyprojectheaderassignment_CompanyProjectID` (`CompanyProjectID`);
ALTER TABLE `companyprojectheaderassignment` ADD INDEX `companyprojectheaderassignment_DivisionID` (`DivisionID`);
ALTER TABLE `companyprojectheaderassignment` ADD INDEX `companyprojectheaderassignment_IndustryID` (`IndustryID`);
ALTER TABLE `companyprojectheaderassignment` ADD INDEX `companyprojectheaderassignment_ProjectID` (`ProjectID`);
ALTER TABLE `companyprojectheaderassignment` ADD INDEX `companyprojectheaderassignment_ProjectPriority` (`ProjectPriority`);
ALTER TABLE `companyprojectheaderassignment` ADD INDEX `companyprojectheaderassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `companyprojectheaderassignment` ADD INDEX `companyprojectheaderassignment_UserIDSales` (`UserIDSales`);
ALTER TABLE `complain` ADD INDEX `complain_CompanyCPID` (`CompanyCPID`);
ALTER TABLE `complain` ADD INDEX `complain_CompanyID` (`CompanyID`);
ALTER TABLE `complain` ADD INDEX `complain_ComplainReasonID` (`ComplainReasonID`);
ALTER TABLE `complain` ADD INDEX `complain_ComplainTypeID` (`ComplainTypeID`);
ALTER TABLE `complain` ADD INDEX `complain_DivisionID` (`DivisionID`);
ALTER TABLE `complain` ADD INDEX `complain_UserIDInput` (`UserIDInput`);
ALTER TABLE `complain` ADD INDEX `complain_UserIDSales` (`UserIDSales`);
ALTER TABLE `complain` ADD INDEX `ComplainStatusID` (`ComplainStatusID`,`ComplainTypeID`,`DivisionID`,`CompanyID`,`CompanyCPID`,`UserIDInput`,`UserIDSales`);
ALTER TABLE `complainassignment` ADD INDEX `complainassignment_ComplainStatusID` (`ComplainStatusID`);
ALTER TABLE `complainassignment` ADD INDEX `complainassignment_UserID` (`UserID`);
ALTER TABLE `complainassignment` ADD INDEX `ComplainID` (`ComplainID`,`ComplainStatusID`,`UserID`);
ALTER TABLE `complaindetails` ADD INDEX `complaindetails_ApplicationID` (`ApplicationID`);
ALTER TABLE `complaindetails` ADD INDEX `complaindetails_BarangID` (`BarangID`);
ALTER TABLE `complaindetails` ADD INDEX `complaindetails_ComplainDetailsStatusID` (`ComplainDetailsStatusID`);
ALTER TABLE `complaindetails` ADD INDEX `complaindetails_PrincipalID` (`PrincipalID`);
ALTER TABLE `complaindetails` ADD INDEX `complaindetails_SatuanComplainQuantityID` (`SatuanComplainQuantityID`);
ALTER TABLE `complaindetails` ADD INDEX `complaindetails_SatuanPackingID` (`SatuanPackingID`);
ALTER TABLE `complaindetails` ADD INDEX `complaindetails_SatuanUnitPriceUSD` (`SatuanUnitPriceUSD`);
ALTER TABLE `complaindetails` ADD INDEX `ComplainID` (`ComplainID`,`ComplainDetailsStatusID`,`PrincipalID`,`BarangID`,`ApplicationID`,`SatuanPackingID`,`BarangListID`,`SatuanComplainQuantityID`);
ALTER TABLE `complaindetailsaction` ADD INDEX `complaindetailsaction_ComplainDetailsID` (`ComplainDetailsID`);
ALTER TABLE `complaindetailsaction` ADD INDEX `complaindetailsaction_ComplainDetailsStatusID` (`ComplainDetailsStatusID`);
ALTER TABLE `complaindetailsaction` ADD INDEX `complaindetailsaction_DepartmentID` (`DepartmentID`);
ALTER TABLE `complaindetailsaction` ADD INDEX `complaindetailsaction_UserID` (`UserID`);
ALTER TABLE `complaindetailsaction` ADD INDEX `ComplainID` (`ComplainID`,`ComplainDetailsID`,`ComplainDetailsStatusID`,`DepartmentID`,`UserID`);
ALTER TABLE `complaindetailsactionassignment` ADD INDEX `complaindetailsactionassignment_ComplainDetailsID` (`ComplainDetailsID`);
ALTER TABLE `complaindetailsactionassignment` ADD INDEX `complaindetailsactionassignment_ComplainDetailsStatusID` (`ComplainDetailsStatusID`);
ALTER TABLE `complaindetailsactionassignment` ADD INDEX `complaindetailsactionassignment_ComplainID` (`ComplainID`);
ALTER TABLE `complaindetailsactionassignment` ADD INDEX `complaindetailsactionassignment_DepartmentID` (`DepartmentID`);
ALTER TABLE `complaindetailsactionassignment` ADD INDEX `complaindetailsactionassignment_UserID` (`UserID`);
ALTER TABLE `complaindetailsactionassignment` ADD INDEX `ComplainDetailsActionID` (`ComplainDetailsActionID`,`ComplainID`,`ComplainDetailsID`,`ComplainDetailsStatusID`,`DepartmentID`,`UserID`);
ALTER TABLE `complaindetailsassignment` ADD INDEX `complaindetailsassignment_ComplainDetailsID` (`ComplainDetailsID`);
ALTER TABLE `complaindetailsassignment` ADD INDEX `complaindetailsassignment_ComplainDetailsStatusID` (`ComplainDetailsStatusID`);
ALTER TABLE `complaindetailsassignment` ADD INDEX `complaindetailsassignment_DepartmentID` (`DepartmentID`);
ALTER TABLE `complaindetailsassignment` ADD INDEX `complaindetailsassignment_UserID` (`UserID`);
ALTER TABLE `complaindetailsassignment` ADD INDEX `ComplainID` (`ComplainID`,`ComplainDetailsID`,`ComplainDetailsStatusID`,`DepartmentID`,`UserID`);
ALTER TABLE `complainitem` ADD INDEX `complainitem_ComplainStatusID` (`ComplainStatusID`);
ALTER TABLE `complainitem` ADD INDEX `complainitem_ComplainTypeID` (`ComplainTypeID`);
ALTER TABLE `complainitem` ADD INDEX `complainitem_PrincipalID` (`PrincipalID`);
ALTER TABLE `complainitem` ADD INDEX `complainitem_UserIDInput` (`UserIDInput`);
ALTER TABLE `complainitemassignment` ADD INDEX `complainitemassignment_ComplainItemID` (`ComplainItemID`);
ALTER TABLE `complainitemassignment` ADD INDEX `complainitemassignment_ComplainItemStatusID` (`ComplainItemStatusID`);
ALTER TABLE `complainitemassignment` ADD INDEX `complainitemassignment_DepartmentID` (`DepartmentID`);
ALTER TABLE `complainitemassignment` ADD INDEX `complainitemassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `complainitemdetails` ADD INDEX `complainitemdetails_ApplicationID` (`ApplicationID`);
ALTER TABLE `complainitemdetails` ADD INDEX `complainitemdetails_BarangID` (`BarangID`);
ALTER TABLE `complainitemdetails` ADD INDEX `complainitemdetails_CompanyID` (`CompanyID`);
ALTER TABLE `complainitemdetails` ADD INDEX `complainitemdetails_ComplainDetailStatusID` (`ComplainDetailStatusID`);
ALTER TABLE `complainitemdetails` ADD INDEX `complainitemdetails_ComplainItemID` (`ComplainItemID`);
ALTER TABLE `complainitemdetails` ADD INDEX `complainitemdetails_DivisionID` (`DivisionID`);
ALTER TABLE `complainitemdetails` ADD INDEX `complainitemdetails_IndustryID` (`IndustryID`);
ALTER TABLE `complainitemdetails` ADD INDEX `complainitemdetails_PackingMonth` (`PackingMonth`);
ALTER TABLE `complainitemdetails` ADD INDEX `complainitemdetails_PackingYear` (`PackingYear`);
ALTER TABLE `complainitemdetailsaction` ADD INDEX `complainitemdetailsaction_ComplainID` (`ComplainID`);
ALTER TABLE `complainitemdetailsaction` ADD INDEX `complainitemdetailsaction_ComplainStatusID` (`ComplainStatusID`);
ALTER TABLE `complainitemdetailsaction` ADD INDEX `complainitemdetailsaction_DepartmentID` (`DepartmentID`);
ALTER TABLE `complainitemdetailsaction` ADD INDEX `complainitemdetailsaction_UserIDInput` (`UserIDInput`);
ALTER TABLE `complainitemdetailsactionassignment` ADD INDEX `complainitemdetailsactionassignment_ComplainItemID` (`ComplainItemID`);
ALTER TABLE `complainitemdetailsactionassignment` ADD INDEX `complainitemdetailsactionassignment_ComplainItemStatusID` (`ComplainItemStatusID`);
ALTER TABLE `complainitemdetailsactionassignment` ADD INDEX `complainitemdetailsactionassignment_DepartmentID` (`DepartmentID`);
ALTER TABLE `complainitemdetailsactionassignment` ADD INDEX `complainitemdetailsactionassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `complainitemdetailslot` ADD INDEX `complainitemdetailslot_ComplainItemDetailsID` (`ComplainItemDetailsID`);
ALTER TABLE `complainitemdetailslot` ADD INDEX `complainitemdetailslot_ComplainItemID` (`ComplainItemID`);
ALTER TABLE `complainitemdetailslot` ADD INDEX `complainitemdetailslot_PackagingID` (`PackagingID`);
ALTER TABLE `complainitemdetailslotassignment` ADD INDEX `complainitemdetailslotassignment_ComplainItemDetailsID` (`ComplainItemDetailsID`);
ALTER TABLE `complainitemdetailslotassignment` ADD INDEX `complainitemdetailslotassignment_ComplainItemDetailsLotID` (`ComplainItemDetailsLotID`);
ALTER TABLE `complainitemdetailslotassignment` ADD INDEX `complainitemdetailslotassignment_ComplainItemID` (`ComplainItemID`);
ALTER TABLE `complainitemdetailslotassignment` ADD INDEX `complainitemdetailslotassignment_DepartmentID` (`DepID`);
ALTER TABLE `complainitemdetailslotassignment` ADD INDEX `complainitemdetailslotassignment_PackagingID` (`PackagingID`);
ALTER TABLE `complaintosupplier` ADD INDEX `complaintosupplier_ApplicationID` (`ApplicationID`);
ALTER TABLE `complaintosupplier` ADD INDEX `complaintosupplier_CompanyID` (`CompanyID`);
ALTER TABLE `complaintosupplier` ADD INDEX `complaintosupplier_ComplainItemTypeID` (`ComplainItemTypeID`);
ALTER TABLE `complaintosupplier` ADD INDEX `complaintosupplier_ComplainStatusID` (`ComplainStatusID`);
ALTER TABLE `complaintosupplier` ADD INDEX `complaintosupplier_ComplainTypeID` (`ComplainTypeID`);
ALTER TABLE `complaintosupplier` ADD INDEX `complaintosupplier_DivisionID` (`DivisionID`);
ALTER TABLE `complaintosupplier` ADD INDEX `complaintosupplier_IndustryID` (`IndustryID`);
ALTER TABLE `complaintosupplier` ADD INDEX `complaintosupplier_PackingMonth` (`PackingMonth`);
ALTER TABLE `complaintosupplier` ADD INDEX `complaintosupplier_PackingYear` (`PackingYear`);
ALTER TABLE `complaintosupplier` ADD INDEX `complaintosupplier_PrincipalID` (`PrincipalID`);
ALTER TABLE `complaintosupplier` ADD INDEX `complaintosupplier_ProductID` (`ProductID`);
ALTER TABLE `complaintosupplier` ADD INDEX `complaintosupplier_UserIDInput` (`UserIDInput`);
ALTER TABLE `complaintosupplier` ADD INDEX `complaintosupplier_UserIDSales` (`UserIDSales`);
ALTER TABLE `complaintosupplierassignment` ADD INDEX `complaintosupplierassignment_ComplainID` (`ComplainID`);
ALTER TABLE `complaintosupplierassignment` ADD INDEX `complaintosupplierassignment_ComplainStatusID` (`ComplainStatusID`);
ALTER TABLE `complaintosupplierassignment` ADD INDEX `complaintosupplierassignment_DepartmentID` (`DepartmentID`);
ALTER TABLE `complaintosupplierassignment` ADD INDEX `complaintosupplierassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `complaintosupplierdetailsaction` ADD INDEX `complaintosupplierdetailsaction_ComplainID` (`ComplainID`);
ALTER TABLE `complaintosupplierdetailsaction` ADD INDEX `complaintosupplierdetailsaction_ComplainStatusID` (`ComplainStatusID`);
ALTER TABLE `complaintosupplierdetailsaction` ADD INDEX `complaintosupplierdetailsaction_DepartementID` (`DepartementID`);
ALTER TABLE `complaintosupplierdetailsaction` ADD INDEX `complaintosupplierdetailsaction_UserIDInput` (`UserIDInput`);
ALTER TABLE `complaintosupplierdetailsactionassignment` ADD INDEX `complaintosupplierdetailsactionassignment_ComplainID` (`ComplainID`);
ALTER TABLE `complaintosupplierdetailsactionassignment` ADD INDEX `complaintosupplierdetailsactionassignment_ComplainStatusID` (`ComplainStatusID`);
ALTER TABLE `complaintosupplierdetailsactionassignment` ADD INDEX `complaintosupplierdetailsactionassignment_DepartmentID` (`DepartmentID`);
ALTER TABLE `complaintosupplierdetailsactionassignment` ADD INDEX `complaintosupplierdetailsactionassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `division` ADD INDEX `GroupDivisionID` (`GroupDivisionID`);
ALTER TABLE `documentgroupdivision` ADD INDEX `documentgroupdivision_DocID` (`DocID`);
ALTER TABLE `documentgroupdivision` ADD INDEX `documentgroupdivision_GroupDivID` (`GroupDivID`);
ALTER TABLE `documentupload` ADD INDEX `documentupload_DocumentCategoryID` (`DocumentCategoryID`);
ALTER TABLE `documentupload` ADD INDEX `PrincipalID` (`PrincipalID`,`DocumentCategoryID`);
ALTER TABLE `documentuploadinternal` ADD INDEX `DocumentCategoryID` (`DocumentCategoryID`);
ALTER TABLE `izin` ADD INDEX `izin_IzinStatusID` (`IzinStatusID`);
ALTER TABLE `izin` ADD INDEX `izin_IzinTypeStatusID` (`IzinTypeStatusID`);
ALTER TABLE `izin` ADD INDEX `izin_UserIDInput` (`UserIDInput`);
ALTER TABLE `izin` ADD INDEX `izin_UserIDSales` (`UserIDSales`);
ALTER TABLE `izin` ADD INDEX `IzinTypeID` (`IzinTypeID`,`IzinTypeStatusID`,`UserIDInput`,`UserIDSales`,`IzinStatusID`);
ALTER TABLE `izinassignment` ADD INDEX `izinassignment_IzinStatusID` (`IzinStatusID`);
ALTER TABLE `izinassignment` ADD INDEX `izinassignment_UserID` (`UserID`);
ALTER TABLE `izinassignment` ADD INDEX `IzinID` (`IzinID`,`UserID`,`IzinStatusID`);
ALTER TABLE `izintypestatus` ADD INDEX `IzinTypeID` (`IzinTypeID`);
ALTER TABLE `labworkrequest` ADD INDEX `labworkrequest_CompanyCPID` (`CompanyCPID`);
ALTER TABLE `labworkrequest` ADD INDEX `labworkrequest_CompanyID` (`CompanyID`);
ALTER TABLE `labworkrequest` ADD INDEX `labworkrequest_DivisionID` (`DivisionID`);
ALTER TABLE `labworkrequest` ADD INDEX `labworkrequest_IndustryID` (`IndustryID`);
ALTER TABLE `labworkrequest` ADD INDEX `labworkrequest_LabWorkRequestFeedbackStatusID` (`LabWorkRequestFeedbackStatusID`);
ALTER TABLE `labworkrequest` ADD INDEX `labworkrequest_ProjectID` (`ProjectID`);
ALTER TABLE `labworkrequest` ADD INDEX `labworkrequest_UserIDInput` (`UserIDInput`);
ALTER TABLE `labworkrequest` ADD INDEX `labworkrequest_UserIDProjectInitiator` (`UserIDProjectInitiator`);
ALTER TABLE `labworkrequest` ADD INDEX `labworkrequest_UserIDSales` (`UserIDSales`);
ALTER TABLE `labworkrequest` ADD INDEX `LabWorkRequestStatusID` (`LabWorkRequestStatusID`,`UserIDInput`,`UserIDSales`,`DivisionID`,`CompanyID`,`CompanyCPID`,`LabWorkRequestFeedbackStatusID`);
ALTER TABLE `labworkrequestassignment` ADD INDEX `labworkrequestassignment_LabWorkRequestStatusID` (`LabWorkRequestStatusID`);
ALTER TABLE `labworkrequestassignment` ADD INDEX `LabWorkRequestID` (`LabWorkRequestID`,`LabWorkRequestStatusID`);
ALTER TABLE `labworkrequestassignment` ADD INDEX `UserID` (`UserID`);
ALTER TABLE `labworkrequestdetails` ADD INDEX `labworkrequestdetails_BarangID` (`BarangID`);
ALTER TABLE `labworkrequestdetails` ADD INDEX `labworkrequestdetails_LabWorkRequestID` (`LabWorkRequestID`);
ALTER TABLE `labworkrequestdetails` ADD INDEX `labworkrequestdetails_PrincipalID` (`PrincipalID`);
ALTER TABLE `labworkrequestdetails` ADD INDEX `labworkrequestdetails_ProjectID` (`ProjectID`);
ALTER TABLE `labworkrequestdetails` ADD INDEX `labworkrequestdetails_ProjectIDComp` (`ProjectIDComp`);
ALTER TABLE `labworkrequestdetails` ADD INDEX `labworkrequestdetails_SatuanIDUnitPrice` (`SatuanIDUnitPrice`);
ALTER TABLE `labworkrequestdetails` ADD INDEX `labworkrequestdetails_SatuanIDVolume` (`SatuanIDVolume`);
ALTER TABLE `labworkrequestdetails` ADD INDEX `labworkrequestdetails_TypeID` (`TypeID`);
ALTER TABLE `labworkrequestdetails` ADD INDEX `LabWorkRequestDetailStatusID` (`LabWorkRequestDetailStatusID`,`LabWorkRequestID`,`ProductCategory`,`PrincipalID`,`BarangID`,`TypeID`,`SatuanIDVolume`,`SatuanIDUnitPrice`);
ALTER TABLE `labworkrequestdetailsassignment` ADD INDEX `labworkrequestdetailsassignment_LabWorkRequestDetailID` (`LabWorkRequestDetailID`);
ALTER TABLE `labworkrequestdetailsassignment` ADD INDEX `labworkrequestdetailsassignment_LabWorkRequestDetailStatusID` (`LabWorkRequestDetailStatusID`);
ALTER TABLE `labworkrequestdetailsassignment` ADD INDEX `labworkrequestdetailsassignment_UserID` (`UserID`);
ALTER TABLE `labworkrequestdetailsassignment` ADD INDEX `LabWorkRequestID` (`LabWorkRequestID`,`LabWorkRequestDetailID`,`LabWorkRequestDetailStatusID`,`UserID`);
ALTER TABLE `labworkrequestlink` ADD INDEX `labworkrequestlink_LabWorkRequestID` (`LabWorkRequestID`);
ALTER TABLE `lembur` ADD INDEX `lembur_LemburStatusID` (`LemburStatusID`);
ALTER TABLE `lembur` ADD INDEX `lembur_UserIDInput` (`UserIDInput`);
ALTER TABLE `lembur` ADD INDEX `lembur_UserIDSales` (`UserIDSales`);
ALTER TABLE `lembur` ADD INDEX `LemburTypeID` (`LemburTypeID`,`LemburStatusID`,`UserIDInput`,`UserIDSales`);
ALTER TABLE `lemburassignment` ADD INDEX `lemburassignment_LemburStatusID` (`LemburStatusID`);
ALTER TABLE `lemburassignment` ADD INDEX `lemburassignment_UserID` (`UserID`);
ALTER TABLE `lemburassignment` ADD INDEX `LemburID` (`LemburID`,`UserID`,`LemburStatusID`);
ALTER TABLE `menu` ADD INDEX `ParentID` (`ParentID`);
ALTER TABLE `news` ADD INDEX `news_UserID` (`UserID`);
ALTER TABLE `onleave` ADD INDEX `onleave_OnLeaveLimitID` (`OnLeaveLimitID`);
ALTER TABLE `onleave` ADD INDEX `onleave_UserIDInput` (`UserIDInput`);
ALTER TABLE `onleave` ADD INDEX `onleave_UserIDSales` (`UserIDSales`);
ALTER TABLE `onleave` ADD INDEX `onleave_UserPengganti1` (`UserPengganti1`);
ALTER TABLE `onleave` ADD INDEX `onleave_UserPengganti2` (`UserPengganti2`);
ALTER TABLE `onleave` ADD INDEX `OnLeaveStatusID` (`OnLeaveStatusID`,`UserIDInput`,`UserIDSales`,`UserPengganti1`,`UserPengganti2`,`OnLeaveLimitID`);
ALTER TABLE `onleaveadditional` ADD INDEX `onleaveadditional_OnLeaveLimitID` (`OnLeaveLimitID`);
ALTER TABLE `onleaveadditional` ADD INDEX `onleaveadditional_UserID` (`UserID`);
ALTER TABLE `onleaveadditional` ADD INDEX `UserIDInput` (`UserIDInput`,`UserID`,`OnLeaveLimitID`);
ALTER TABLE `onleaveadditionalassignment` ADD INDEX `onleaveadditionalassignment_UserID` (`UserID`);
ALTER TABLE `onleaveadditionalassignment` ADD INDEX `OnLeaveAdditionalID` (`OnLeaveAdditionalID`,`UserID`);
ALTER TABLE `onleaveassignment` ADD INDEX `onleaveassignment_OnLeaveStatusID` (`OnLeaveStatusID`);
ALTER TABLE `onleaveassignment` ADD INDEX `onleaveassignment_UserID` (`UserID`);
ALTER TABLE `onleaveassignment` ADD INDEX `OnLeaveID` (`OnLeaveID`,`UserID`,`OnLeaveStatusID`);
ALTER TABLE `packing` ADD INDEX `SatuanID` (`SatuanID`);
ALTER TABLE `potentialsales` ADD INDEX `CompanyID` (`CompanyID`,`PrincipalID`,`BarangID`);
ALTER TABLE `potentialsales` ADD INDEX `potentialsales_BarangID` (`BarangID`);
ALTER TABLE `potentialsales` ADD INDEX `potentialsales_PrincipalID` (`PrincipalID`);
ALTER TABLE `potentialsaleshistory` ADD INDEX `CompanyID` (`CompanyID`,`PotentialSalesID`,`UserID`,`PrincipalID`,`BarangID`);
ALTER TABLE `potentialsaleshistory` ADD INDEX `potentialsaleshistory_BarangID` (`BarangID`);
ALTER TABLE `potentialsaleshistory` ADD INDEX `potentialsaleshistory_PotentialSalesID` (`PotentialSalesID`);
ALTER TABLE `potentialsaleshistory` ADD INDEX `potentialsaleshistory_PrincipalID` (`PrincipalID`);
ALTER TABLE `potentialsaleshistory` ADD INDEX `potentialsaleshistory_UserID` (`UserID`);
ALTER TABLE `principalcp` ADD INDEX `principalcp_AddressType` (`AddressType`);
ALTER TABLE `principalcp` ADD INDEX `principalcp_PrincipalID` (`PrincipalID`);
ALTER TABLE `principalcpassignment` ADD INDEX `principalcpassignment_AddressType` (`AddressType`);
ALTER TABLE `principalcpassignment` ADD INDEX `principalcpassignment_PrincipalCPID` (`PrincipalCPID`);
ALTER TABLE `principalcpassignment` ADD INDEX `principalcpassignment_PrincipalID` (`PrincipalID`);
ALTER TABLE `principalcpassignment` ADD INDEX `principalcpassignment_UsersID` (`UsersID`);
ALTER TABLE `principalfaq` ADD INDEX `principalfaq_PrincipalID` (`PrincipalID`);
ALTER TABLE `principalfaqhistory` ADD INDEX `principalfaqhistory_PrincipalFAQID` (`PrincipalFAQID`);
ALTER TABLE `principalfaqhistory` ADD INDEX `principalfaqhistory_PrincipalID` (`PrincipalID`);
ALTER TABLE `printeditemfulfillment` ADD INDEX `printeditemfulfillment_UserIDInput` (`UserIDInput`);
ALTER TABLE `product` ADD INDEX `ClassID` (`ClassID`,`PrincipalID`,`PackingID`);
ALTER TABLE `product` ADD INDEX `product_PackingID` (`PackingID`);
ALTER TABLE `product` ADD INDEX `product_PrincipalID` (`PrincipalID`);
ALTER TABLE `productapplication` ADD INDEX `productapplication_ApplicationID` (`ApplicationID`);
ALTER TABLE `productapplication` ADD INDEX `productapplication_ProductID` (`ProductID`);
ALTER TABLE `productapplication` ADD INDEX `UserIDInput` (`UserIDInput`,`ProductID`,`ApplicationID`);
ALTER TABLE `productcategory` ADD INDEX `productcategory_CategoryID` (`CategoryID`);
ALTER TABLE `productcategory` ADD INDEX `productcategory_ProductID` (`ProductID`);
ALTER TABLE `productcategory` ADD INDEX `UserIDInput` (`UserIDInput`,`CategoryID`,`ProductID`);
ALTER TABLE `proposedcreditceiling` ADD INDEX `CompanyID` (`CompanyID`,`CCStatusID`,`UserIDInput`,`JustificationID`,`QuotationPaymentTermApprovedID`);
ALTER TABLE `proposedcreditceiling` ADD INDEX `proposedcreditceiling_CCStatusID` (`CCStatusID`);
ALTER TABLE `proposedcreditceiling` ADD INDEX `proposedcreditceiling_JustificationID` (`JustificationID`);
ALTER TABLE `proposedcreditceiling` ADD INDEX `proposedcreditceiling_QuotationPaymentTermApprovedID` (`QuotationPaymentTermApprovedID`);
ALTER TABLE `proposedcreditceiling` ADD INDEX `proposedcreditceiling_UserIDInput` (`UserIDInput`);
ALTER TABLE `proposedcreditceiling` ADD INDEX `QuotationPaymentTermID` (`QuotationPaymentTermID`);
ALTER TABLE `proposedcreditceilinghistory` ADD INDEX `ProposedCCID` (`ProposedCCID`,`CompanyID`,`QuotationPaymentTermID`,`CCStatusID`,`UserID`,`JustificationID`,`QuotationPaymentTermApprovedID`);
ALTER TABLE `proposedcreditceilinghistory` ADD INDEX `proposedcreditceilinghistory_CCStatusID` (`CCStatusID`);
ALTER TABLE `proposedcreditceilinghistory` ADD INDEX `proposedcreditceilinghistory_CompanyID` (`CompanyID`);
ALTER TABLE `proposedcreditceilinghistory` ADD INDEX `proposedcreditceilinghistory_JustificationID` (`JustificationID`);
ALTER TABLE `proposedcreditceilinghistory` ADD INDEX `proposedcreditceilinghistory_QuotationPaymentTermApprovedID` (`QuotationPaymentTermApprovedID`);
ALTER TABLE `proposedcreditceilinghistory` ADD INDEX `proposedcreditceilinghistory_QuotationPaymentTermID` (`QuotationPaymentTermID`);
ALTER TABLE `proposedcreditceilinghistory` ADD INDEX `proposedcreditceilinghistory_UserID` (`UserID`);
ALTER TABLE `purchaseorder` ADD INDEX `purchaseorder_PurchaseOrderStatusID` (`PurchaseOrderStatusID`);
ALTER TABLE `purchaseorder` ADD INDEX `purchaseorder_UserIDInput` (`UserIDInput`);
ALTER TABLE `purchaseorderassignment` ADD INDEX `purchaseorderassignment_PurchaseOrderID` (`PurchaseOrderID`);
ALTER TABLE `purchaseorderassignment` ADD INDEX `purchaseorderassignment_PurchaseOrderStatusID` (`PurchaseOrderStatusID`);
ALTER TABLE `purchaseorderassignment` ADD INDEX `purchaseorderassignment_UserID` (`UserID`);
ALTER TABLE `purchaseorderdetails` ADD INDEX `purchaseorderdetails_PackingID` (`PackingID`);
ALTER TABLE `purchaseorderdetails` ADD INDEX `purchaseorderdetails_PurchaseOrderDetailStatusID` (`PurchaseOrderDetailStatusID`);
ALTER TABLE `purchaseorderdetails` ADD INDEX `purchaseorderdetails_PurchaseOrderID` (`PurchaseOrderID`);
ALTER TABLE `purchaseorderdetails` ADD INDEX `purchaseorderdetails_SatuanID` (`SatuanID`);
ALTER TABLE `purchaseorderdetails` ADD INDEX `purchaseorderdetails_SatuanOrderQtyID` (`SatuanOrderQtyID`);
ALTER TABLE `purchaseorderdetailsassignment` ADD INDEX `purchaseorderdetailsassignment_PurchaseOrderDetailID` (`PurchaseOrderDetailID`);
ALTER TABLE `purchaseorderdetailsassignment` ADD INDEX `purchaseorderdetailsassignment_PurchaseOrderID` (`PurchaseOrderID`);
ALTER TABLE `purchaseorderdetailsassignment` ADD INDEX `purchaseorderdetailsassignment_PurchaseOrderStatusID` (`PurchaseOrderStatusID`);
ALTER TABLE `purchaseorderdetailsassignment` ADD INDEX `purchaseorderdetailsassignment_UserID` (`UserID`);
ALTER TABLE `purchaseorderhargajual` ADD INDEX `purchaseorderhargajual_UserIDInput` (`UserIDInput`);
ALTER TABLE `quotation` ADD INDEX `quotation_CompanyCPID` (`CompanyCPID`);
ALTER TABLE `quotation` ADD INDEX `quotation_CompanyID` (`CompanyID`);
ALTER TABLE `quotation` ADD INDEX `quotation_DeliveryAddressID` (`DeliveryAddressID`);
ALTER TABLE `quotation` ADD INDEX `quotation_DivisionID` (`DivisionID`);
ALTER TABLE `quotation` ADD INDEX `quotation_InvoiceAddressID` (`InvoiceAddressID`);
ALTER TABLE `quotation` ADD INDEX `quotation_QuotationDeliveryTimeID` (`QuotationDeliveryTimeID`);
ALTER TABLE `quotation` ADD INDEX `quotation_QuotationFeedbackStatusID` (`QuotationFeedbackStatusID`);
ALTER TABLE `quotation` ADD INDEX `quotation_QuotationPaymentTermID` (`QuotationPaymentTermID`);
ALTER TABLE `quotation` ADD INDEX `quotation_QuotationPriceDescID` (`QuotationPriceDescID`);
ALTER TABLE `quotation` ADD INDEX `quotation_QuotationSalesTermID` (`QuotationSalesTermID`);
ALTER TABLE `quotation` ADD INDEX `quotation_QuotationStatusID` (`QuotationStatusID`);
ALTER TABLE `quotation` ADD INDEX `quotation_QuotationStockAvailibilityID` (`QuotationStockAvailibilityID`);
ALTER TABLE `quotation` ADD INDEX `quotation_QuotationSubjectID` (`QuotationSubjectID`);
ALTER TABLE `quotation` ADD INDEX `quotation_QuotationTitleID` (`QuotationTitleID`);
ALTER TABLE `quotation` ADD INDEX `quotation_QuotationTypeID` (`QuotationTypeID`);
ALTER TABLE `quotation` ADD INDEX `quotation_QuotationValidityID` (`QuotationValidityID`);
ALTER TABLE `quotation` ADD INDEX `quotation_ReferenceQuotationID` (`ReferenceQuotationID`);
ALTER TABLE `quotation` ADD INDEX `quotation_UserIDInput` (`UserIDInput`);
ALTER TABLE `quotation` ADD INDEX `quotation_UserIDSales` (`UserIDSales`);
ALTER TABLE `quotationassignment` ADD INDEX `qta_fk_QuotationID` (`QuotationID`);
ALTER TABLE `quotationassignment` ADD INDEX `qta_fk_QuotationStatusID` (`QuotationStatusID`);
ALTER TABLE `quotationassignment` ADD INDEX `qta_fk_UserID` (`UserID`);
ALTER TABLE `quotationdetails` ADD INDEX `quotationdetails_ApplicationID` (`ApplicationID`);
ALTER TABLE `quotationdetails` ADD INDEX `quotationdetails_BarangID` (`BarangID`);
ALTER TABLE `quotationdetails` ADD INDEX `quotationdetails_ItemOriginID` (`ItemOriginID`);
ALTER TABLE `quotationdetails` ADD INDEX `quotationdetails_PackingID` (`PackingID`);
ALTER TABLE `quotationdetails` ADD INDEX `quotationdetails_ProjectID` (`ProjectID`);
ALTER TABLE `quotationdetails` ADD INDEX `quotationdetails_ProjectIDDetails` (`ProjectIDDetails`);
ALTER TABLE `quotationdetails` ADD INDEX `quotationdetails_QuotationDetailStatusID` (`QuotationDetailStatusID`);
ALTER TABLE `quotationdetails` ADD INDEX `quotationdetails_QuotationID` (`QuotationID`);
ALTER TABLE `quotationdetails` ADD INDEX `quotationdetails_QuotationPackID` (`QuotationPackID`);
ALTER TABLE `quotationdetails` ADD INDEX `quotationdetails_SatuanID` (`SatuanID`);
ALTER TABLE `quotationdetails` ADD INDEX `quotationdetails_SatuanOrderQty` (`SatuanOrderQty`);
ALTER TABLE `quotationdetailsassignment` ADD INDEX `qda_fk_QuotationDetailID` (`QuotationDetailID`);
ALTER TABLE `quotationdetailsassignment` ADD INDEX `qda_fk_QuotationDetailStatusID` (`QuotationDetailStatusID`);
ALTER TABLE `quotationdetailsassignment` ADD INDEX `qda_fk_QuotationID` (`QuotationID`);
ALTER TABLE `quotationdetailsassignment` ADD INDEX `qda_fk_UserID` (`UserID`);
ALTER TABLE `quotationlink` ADD INDEX `ql_fk_QuotationID` (`QuotationID`);
ALTER TABLE `reference` ADD INDEX `CompanyID` (`CompanyID`);
ALTER TABLE `reference` ADD INDEX `reference_PaymentTerm` (`PaymentTerm`);
ALTER TABLE `referencehistory` ADD INDEX `referencehistory_CompanyID` (`CompanyID`);
ALTER TABLE `referencehistory` ADD INDEX `referencehistory_PaymentTerm` (`PaymentTerm`);
ALTER TABLE `referencehistory` ADD INDEX `referencehistory_UserID` (`UserID`);
ALTER TABLE `referencehistory` ADD INDEX `ReferenceID` (`ReferenceID`,`UserID`,`CompanyID`);
ALTER TABLE `relabelhistory` ADD INDEX `relabelhistory_UserIDInput` (`UserIDInput`);
ALTER TABLE `rolegadget` ADD INDEX `rolegadget_GadgetID` (`GadgetID`);
ALTER TABLE `rolegadget` ADD INDEX `RoleID` (`RoleID`,`GadgetID`);
ALTER TABLE `rolemenu` ADD INDEX `RoleID` (`RoleID`,`MenuID`);
ALTER TABLE `rolemenu` ADD INDEX `rolemenu_MenuID` (`MenuID`);
ALTER TABLE `salesrebate` ADD INDEX `salesrebate_CCPaymentTerm` (`CCPaymentTerm`);
ALTER TABLE `salesrebate` ADD INDEX `salesrebate_CompanyID` (`CompanyID`);
ALTER TABLE `salesrebate` ADD INDEX `salesrebate_DivisionID` (`DivisionID`);
ALTER TABLE `salesrebate` ADD INDEX `salesrebate_IndustryID` (`IndustryID`);
ALTER TABLE `salesrebate` ADD INDEX `salesrebate_ReferenceRebateID` (`ReferenceRebateID`);
ALTER TABLE `salesrebate` ADD INDEX `salesrebate_SalesRebateStatusID` (`SalesRebateStatusID`);
ALTER TABLE `salesrebate` ADD INDEX `salesrebate_UserIDInput` (`UserIDInput`);
ALTER TABLE `salesrebate` ADD INDEX `salesrebate_UserIDSales` (`UserIDSales`);
ALTER TABLE `salesrebateassignment` ADD INDEX `salesrebateassignment_SalesRebateID` (`SalesRebateID`);
ALTER TABLE `salesrebateassignment` ADD INDEX `salesrebateassignment_SalesRebateStatusID` (`SalesRebateStatusID`);
ALTER TABLE `salesrebateassignment` ADD INDEX `salesrebateassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `salesrebatedetail` ADD INDEX `salesrebatedetail_CompanyCPID` (`CompanyCPID`);
ALTER TABLE `salesrebatedetail` ADD INDEX `salesrebatedetail_SalesRebateID` (`SalesRebateID`);
ALTER TABLE `salesrebateinvoice` ADD INDEX `salesrebateinvoice_CompanyID` (`CompanyID`);
ALTER TABLE `salesrebateinvoice` ADD INDEX `salesrebateinvoice_DivisionID` (`DivisionID`);
ALTER TABLE `salesrebateinvoice` ADD INDEX `salesrebateinvoice_IndustryID` (`IndustryID`);
ALTER TABLE `salesrebateinvoice` ADD INDEX `salesrebateinvoice_SalesRebateID` (`SalesRebateID`);
ALTER TABLE `salesrebateinvoice` ADD INDEX `salesrebateinvoice_SalesRebateInvoiceStatusID` (`SalesRebateInvoiceStatusID`);
ALTER TABLE `salesrebateinvoice` ADD INDEX `salesrebateinvoice_UserInput` (`UserInput`);
ALTER TABLE `salesrebateinvoiceassignment` ADD INDEX `salesrebateinvoiceassignment_SalesRebateInvoiceID` (`SalesRebateInvoiceID`);
ALTER TABLE `salesrebateinvoiceassignment` ADD INDEX `salesrebateinvoiceassignment_SalesRebateInvoiceStatusID` (`SalesRebateInvoiceStatusID`);
ALTER TABLE `salesrebateinvoiceassignment` ADD INDEX `salesrebateinvoiceassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `salesrebateinvoicedetail` ADD INDEX `salesrebateinvoicedetail_PaymentCPID` (`PaymentCPID`);
ALTER TABLE `salesrebateinvoicedetail` ADD INDEX `salesrebateinvoicedetail_SalesRebateID` (`SalesRebateID`);
ALTER TABLE `salesrebateinvoicedetail` ADD INDEX `salesrebateinvoicedetail_SalesRebateInvoiceDetailStatusID` (`SalesRebateInvoiceDetailStatusID`);
ALTER TABLE `salesrebateinvoicedetail` ADD INDEX `salesrebateinvoicedetail_SalesRebateInvoiceID` (`SalesRebateInvoiceID`);
ALTER TABLE `salesrebateinvoicepaymentdetail` ADD INDEX `salesrebateinvoicepaymentdetail_SalesRebateInvoiceDetailID` (`SalesRebateInvoiceDetailID`);
ALTER TABLE `sampleorder` ADD INDEX `sampleorder_CompanyCPID` (`CompanyCPID`);
ALTER TABLE `sampleorder` ADD INDEX `sampleorder_CompanyID` (`CompanyID`);
ALTER TABLE `sampleorder` ADD INDEX `sampleorder_DeliveryID` (`DeliveryID`);
ALTER TABLE `sampleorder` ADD INDEX `sampleorder_DivisionID` (`DivisionID`);
ALTER TABLE `sampleorder` ADD INDEX `sampleorder_IndustryID` (`IndustryID`);
ALTER TABLE `sampleorder` ADD INDEX `sampleorder_LocationID` (`LocationID`);
ALTER TABLE `sampleorder` ADD INDEX `sampleorder_PriorityID` (`PriorityID`);
ALTER TABLE `sampleorder` ADD INDEX `sampleorder_ProjectID` (`ProjectID`);
ALTER TABLE `sampleorder` ADD INDEX `sampleorder_ReferenceSOID` (`ReferenceSOID`);
ALTER TABLE `sampleorder` ADD INDEX `sampleorder_SampleOrderByID` (`SampleOrderByID`);
ALTER TABLE `sampleorder` ADD INDEX `sampleorder_SampleOrderFeedbackStatusID` (`SampleOrderFeedbackStatusID`);
ALTER TABLE `sampleorder` ADD INDEX `sampleorder_UserIDInput` (`UserIDInput`);
ALTER TABLE `sampleorder` ADD INDEX `sampleorder_UserIDSales` (`UserIDSales`);
ALTER TABLE `sampleorder` ADD INDEX `SampleOrderStatusID` (`SampleOrderStatusID`,`ReferenceSOID`,`DeliveryID`,`CompanyID`,`CompanyCPID`,`LocationID`,`DivisionID`,`PriorityID`,`SampleOrderFeedbackStatusID`,`SampleOrderByID`);
ALTER TABLE `sampleorderassignment` ADD INDEX `sampleorderassignment_SampleOrderStatusID` (`SampleOrderStatusID`);
ALTER TABLE `sampleorderassignment` ADD INDEX `sampleorderassignment_UserID` (`UserID`);
ALTER TABLE `sampleorderassignment` ADD INDEX `SampleOrderID` (`SampleOrderID`,`SampleOrderStatusID`,`UserID`);
ALTER TABLE `sampleorderdetail` ADD INDEX `sampleorderdetail_ApplicationID` (`ApplicationID`);
ALTER TABLE `sampleorderdetail` ADD INDEX `sampleorderdetail_BarangID` (`BarangID`);
ALTER TABLE `sampleorderdetail` ADD INDEX `sampleorderdetail_BarangListID` (`BarangListID`);
ALTER TABLE `sampleorderdetail` ADD INDEX `sampleorderdetail_BarangListIDRequest` (`BarangListIDRequest`);
ALTER TABLE `sampleorderdetail` ADD INDEX `sampleorderdetail_ProjectID` (`ProjectID`);
ALTER TABLE `sampleorderdetail` ADD INDEX `sampleorderdetail_ProjectIDDetails` (`ProjectIDDetails`);
ALTER TABLE `sampleorderdetail` ADD INDEX `sampleorderdetail_SampleOrderDetailStatusID` (`SampleOrderDetailStatusID`);
ALTER TABLE `sampleorderdetail` ADD INDEX `sampleorderdetail_SatuanID` (`SatuanID`);
ALTER TABLE `sampleorderdetail` ADD INDEX `sampleorderdetail_SuratJalanDetailID` (`SuratJalanDetailID`);
ALTER TABLE `sampleorderdetail` ADD INDEX `SampleOrderID` (`SampleOrderID`,`SampleOrderDetailStatusID`,`BarangID`,`SatuanID`,`ApplicationID`,`BarangListID`,`SuratJalanDetailID`);
ALTER TABLE `sampleorderdetailassignment` ADD INDEX `sampleorderdetailassignment_SampleOrderDetailID` (`SampleOrderDetailID`);
ALTER TABLE `sampleorderdetailassignment` ADD INDEX `sampleorderdetailassignment_SampleOrderDetailStatusID` (`SampleOrderDetailStatusID`);
ALTER TABLE `sampleorderdetailassignment` ADD INDEX `sampleorderdetailassignment_UserID` (`UserID`);
ALTER TABLE `sampleorderdetailassignment` ADD INDEX `SampleOrderID` (`SampleOrderID`,`SampleOrderDetailID`,`SampleOrderDetailStatusID`,`UserID`);
ALTER TABLE `sampleorderlink` ADD INDEX `sampleorderlink_SampleOrderID` (`SampleOrderID`);
ALTER TABLE `samplerequestimport` ADD INDEX `samplerequestimport_DeliveryID` (`DeliveryID`);
ALTER TABLE `samplerequestimport` ADD INDEX `samplerequestimport_PrincipalID` (`PrincipalID`);
ALTER TABLE `samplerequestimport` ADD INDEX `samplerequestimport_ReferenceSRID` (`ReferenceSRID`);
ALTER TABLE `samplerequestimport` ADD INDEX `samplerequestimport_RequestFromID` (`RequestFromID`);
ALTER TABLE `samplerequestimport` ADD INDEX `samplerequestimport_UrgencyID` (`UrgencyID`);
ALTER TABLE `samplerequestimport` ADD INDEX `samplerequestimport_UserIDInput` (`UserIDInput`);
ALTER TABLE `samplerequestimport` ADD INDEX `SampleRequestStatusID` (`SampleRequestStatusID`,`ReferenceSRID`,`UserIDInput`,`PrincipalID`,`DeliveryID`,`UrgencyID`,`RequestFromID`);
ALTER TABLE `samplerequestimportassignment` ADD INDEX `samplerequestimportassignment_SampleRequestStatusID` (`SampleRequestStatusID`);
ALTER TABLE `samplerequestimportassignment` ADD INDEX `samplerequestimportassignment_UserID` (`UserID`);
ALTER TABLE `samplerequestimportassignment` ADD INDEX `SampleRequestImportID` (`SampleRequestImportID`,`SampleRequestStatusID`,`UserID`);
ALTER TABLE `samplerequestimportdetail` ADD INDEX `samplerequestimportdetail_BarangID` (`BarangID`);
ALTER TABLE `samplerequestimportdetail` ADD INDEX `samplerequestimportdetail_BaranglistID` (`BaranglistID`);
ALTER TABLE `samplerequestimportdetail` ADD INDEX `samplerequestimportdetail_GoodReceiptDetailID` (`GoodReceiptDetailID`);
ALTER TABLE `samplerequestimportdetail` ADD INDEX `samplerequestimportdetail_ReqCompanyID` (`ReqCompanyID`);
ALTER TABLE `samplerequestimportdetail` ADD INDEX `samplerequestimportdetail_SampleRequestDetailStatusID` (`SampleRequestDetailStatusID`);
ALTER TABLE `samplerequestimportdetail` ADD INDEX `samplerequestimportdetail_SatuanID` (`SatuanID`);
ALTER TABLE `samplerequestimportdetail` ADD INDEX `SampleRequestImportID` (`SampleRequestImportID`,`SampleRequestDetailStatusID`,`BarangID`,`SatuanID`,`ReqCompanyID`,`GoodReceiptDetailID`,`BaranglistID`);
ALTER TABLE `samplerequestimportdetailassignment` ADD INDEX `samplerequestimportdetailassignment_SampleRequestDetailID` (`SampleRequestDetailID`);
ALTER TABLE `samplerequestimportdetailassignment` ADD INDEX `samplerequestimportdetailassignment_SampleRequestDetailStatusID` (`SampleRequestDetailStatusID`);
ALTER TABLE `samplerequestimportdetailassignment` ADD INDEX `samplerequestimportdetailassignment_UserID` (`UserID`);
ALTER TABLE `samplerequestimportdetailassignment` ADD INDEX `SampleRequestImportID` (`SampleRequestImportID`,`SampleRequestDetailID`,`SampleRequestDetailStatusID`,`UserID`);
ALTER TABLE `samplerequestimportgoodsreceipt` ADD INDEX `samplerequestimportgoodsreceipt_BarangID` (`BarangID`);
ALTER TABLE `samplerequestimportgoodsreceipt` ADD INDEX `samplerequestimportgoodsreceipt_BarangListsID` (`BarangListsID`);
ALTER TABLE `samplerequestimportgoodsreceipt` ADD INDEX `samplerequestimportgoodsreceipt_SampleRequestImportDetailID` (`SampleRequestImportDetailID`);
ALTER TABLE `samplerequestimportgoodsreceipt` ADD INDEX `samplerequestimportgoodsreceipt_SatuanID` (`SatuanID`);
ALTER TABLE `samplerequestimportgoodsreceipt` ADD INDEX `SampleRequestImportID` (`SampleRequestImportID`,`SampleRequestImportDetailID`,`BarangID`,`SatuanID`,`BarangListsID`);
ALTER TABLE `specialreference` ADD INDEX `CompanyID` (`CompanyID`);
ALTER TABLE `specialreferencehistory` ADD INDEX `specialreferencehistory_CompanyID` (`CompanyID`);
ALTER TABLE `specialreferencehistory` ADD INDEX `specialreferencehistory_UserID` (`UserID`);
ALTER TABLE `specialreferencehistory` ADD INDEX `SpecialReferenceID` (`SpecialReferenceID`,`UserID`,`CompanyID`);
ALTER TABLE `stockopname` ADD INDEX `stockopname_PackagingID` (`PackagingID`);
ALTER TABLE `stockopname` ADD INDEX `stockopname_PrincipalID` (`PrincipalID`);
ALTER TABLE `stockopname` ADD INDEX `stockopname_ProductID` (`ProductID`);
ALTER TABLE `stockopname` ADD INDEX `stockopname_StockOpnameBy` (`StockOpnameBy`);
ALTER TABLE `stockopname` ADD INDEX `stockopname_UOMID` (`UOMID`);
ALTER TABLE `stockopname` ADD INDEX `stockopname_WarehouseID` (`WarehouseID`);
ALTER TABLE `stockopname_product` ADD INDEX `stockopname_product_PrincipalID` (`PrincipalID`);
ALTER TABLE `stockopnamehistory` ADD INDEX `stockopnamehistory_PackagingID` (`PackagingID`);
ALTER TABLE `stockopnamehistory` ADD INDEX `stockopnamehistory_PrincipalID` (`PrincipalID`);
ALTER TABLE `stockopnamehistory` ADD INDEX `stockopnamehistory_ProductID` (`ProductID`);
ALTER TABLE `stockopnamehistory` ADD INDEX `stockopnamehistory_StockOpnameBy` (`StockOpnameBy`);
ALTER TABLE `stockopnamehistory` ADD INDEX `stockopnamehistory_StockOpnameID` (`StockOpnameID`);
ALTER TABLE `stockopnamehistory` ADD INDEX `stockopnamehistory_StockOpnameStatusID` (`StockOpnameStatusID`);
ALTER TABLE `stockopnamehistory` ADD INDEX `stockopnamehistory_UOMID` (`UOMID`);
ALTER TABLE `stockopnamehistory` ADD INDEX `stockopnamehistory_WarehouseID` (`WarehouseID`);
ALTER TABLE `successstory` ADD INDEX `successstory_ApplicationID` (`ApplicationID`);
ALTER TABLE `successstory` ADD INDEX `successstory_BarangID` (`BarangID`);
ALTER TABLE `successstory` ADD INDEX `successstory_DivisionID` (`DivisionID`);
ALTER TABLE `successstory` ADD INDEX `successstory_GroupDivisionID` (`GroupDivisionID`);
ALTER TABLE `successstory` ADD INDEX `successstory_PrincipalID` (`PrincipalID`);
ALTER TABLE `successstory` ADD INDEX `successstory_UserIDSales` (`UserIDSales`);
ALTER TABLE `successstory` ADD INDEX `UserIDInput` (`UserIDInput`,`UserIDSales`,`GroupDivisionID`,`DivisionID`,`ApplicationID`,`PrincipalID`,`BarangID`);
ALTER TABLE `successstoryassignment` ADD INDEX `successstoryassignment_UserID` (`UserID`);
ALTER TABLE `successstoryassignment` ADD INDEX `SuccessStoryID` (`SuccessStoryID`,`Tanggal`,`UserID`);
ALTER TABLE `suratjalan` ADD INDEX `SampleOrderID` (`SampleOrderID`,`DeliveryID`,`CompanyID`,`CompanyCPID`,`LocationID`,`UserIDsales`,`UserIDCreatorSJ`);
ALTER TABLE `suratjalan` ADD INDEX `suratjalan_CompanyCPID` (`CompanyCPID`);
ALTER TABLE `suratjalan` ADD INDEX `suratjalan_CompanyID` (`CompanyID`);
ALTER TABLE `suratjalan` ADD INDEX `suratjalan_DeliveryID` (`DeliveryID`);
ALTER TABLE `suratjalan` ADD INDEX `suratjalan_LocationID` (`LocationID`);
ALTER TABLE `suratjalan` ADD INDEX `suratjalan_UserIDCreatorSJ` (`UserIDCreatorSJ`);
ALTER TABLE `suratjalan` ADD INDEX `suratjalan_UserIDsales` (`UserIDsales`);
ALTER TABLE `suratjalandetails` ADD INDEX `suratjalandetails_ApplicationID` (`ApplicationID`);
ALTER TABLE `suratjalandetails` ADD INDEX `suratjalandetails_BarangID` (`BarangID`);
ALTER TABLE `suratjalandetails` ADD INDEX `suratjalandetails_BarangListID` (`BarangListID`);
ALTER TABLE `suratjalandetails` ADD INDEX `suratjalandetails_SampleOrderID` (`SampleOrderID`);
ALTER TABLE `suratjalandetails` ADD INDEX `suratjalandetails_SatuanID` (`SatuanID`);
ALTER TABLE `suratjalandetails` ADD INDEX `SuratJalanID` (`SuratJalanID`,`SampleOrderID`,`BarangID`,`SatuanID`,`ApplicationID`,`BarangListID`);
ALTER TABLE `userbusinesstravelbranch` ADD INDEX `userbusinesstravelbranch_BranchID` (`BranchID`);
ALTER TABLE `userbusinesstravelbranch` ADD INDEX `userbusinesstravelbranch_UserID` (`UserID`);
ALTER TABLE `userdetails` ADD INDEX `BranchID` (`BranchID`,`DepartmentID`,`DivisionID`,`MaritalStatus`);
ALTER TABLE `userdetails` ADD INDEX `userdetails_DepartmentID` (`DepartmentID`);
ALTER TABLE `userdetails` ADD INDEX `userdetails_DivisionID` (`DivisionID`);
ALTER TABLE `userdivision` ADD INDEX `userdivision_DivisionID` (`DivisionID`);
ALTER TABLE `userdivision` ADD INDEX `UserID` (`UserID`,`DivisionID`);
ALTER TABLE `usereducation` ADD INDEX `usereducation_EducationID` (`EducationID`);
ALTER TABLE `usereducation` ADD INDEX `UserID` (`UserID`,`EducationID`);
ALTER TABLE `userjob` ADD INDEX `UserID` (`UserID`);
ALTER TABLE `userlabgroupdivision` ADD INDEX `userlabgroupdivision_GroupDivisionID` (`GroupDivisionID`);
ALTER TABLE `userlabgroupdivision` ADD INDEX `userlabgroupdivision_UserID` (`UserID`);
ALTER TABLE `userprincipal` ADD INDEX `UserID` (`UserID`,`PrincipalID`);
ALTER TABLE `userprincipal` ADD INDEX `userprincipal_PrincipalID` (`PrincipalID`);
ALTER TABLE `users` ADD INDEX `DepartmentID` (`DepartmentID`,`RoleID`,`MaritalStatusID`,`BranchID`,`HeadID`);
ALTER TABLE `users` ADD INDEX `users_BranchID` (`BranchID`);
ALTER TABLE `users` ADD INDEX `users_HeadID` (`HeadID`);
ALTER TABLE `users` ADD INDEX `users_MaritalStatusID` (`MaritalStatusID`);
ALTER TABLE `users` ADD INDEX `users_RoleID` (`RoleID`);
ALTER TABLE `usersperiode` ADD INDEX `usersperiode_UserID` (`UserID`);
ALTER TABLE `userwarehouse` ADD INDEX `userwarehouse_WarehouseID` (`WarehouseID`);
ALTER TABLE `vehicle` ADD INDEX `UserIDInput` (`UserIDInput`,`UserIDOwner`,`VehicleTypeID`,`VehicleBrandID`,`VehicleBrandTypeID`,`VehicleColorID`,`VehicleFuelTypeID`,`GasolineID`);
ALTER TABLE `vehicle` ADD INDEX `vehicle_UserIDOwner` (`UserIDOwner`);
ALTER TABLE `vehicle` ADD INDEX `vehicle_VehicleBrandID` (`VehicleBrandID`);
ALTER TABLE `vehicle` ADD INDEX `vehicle_VehicleBrandTypeID` (`VehicleBrandTypeID`);
ALTER TABLE `vehicle` ADD INDEX `vehicle_VehicleColorID` (`VehicleColorID`);
ALTER TABLE `vehicle` ADD INDEX `vehicle_VehicleFuelTypeID` (`VehicleFuelTypeID`);
ALTER TABLE `vehicle` ADD INDEX `vehicle_VehicleTypeID` (`VehicleTypeID`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_UserIDInput` (`UserIDInput`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_UserIDOwnerAfter` (`UserIDOwnerAfter`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_UserIDOwnerBefore` (`UserIDOwnerBefore`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_VehicleBrandIDAfter` (`VehicleBrandIDAfter`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_VehicleBrandIDBefore` (`VehicleBrandIDBefore`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_VehicleBrandTypeIDAfter` (`VehicleBrandTypeIDAfter`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_VehicleBrandTypeIDBefore` (`VehicleBrandTypeIDBefore`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_VehicleColorIDAfter` (`VehicleColorIDAfter`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_VehicleColroIDBefore` (`VehicleColorIDBefore`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_VehicleFuelTypeIDAfter` (`VehicleFuelTypeIDAfter`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_VehicleFuelTypeIDBefore` (`VehicleFuelTypeIDBefore`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_VehicleID` (`VehicleID`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_VehicleStatusID` (`VehicleStatusID`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_VehicleTypeIDAfter` (`VehicleTypeIDAfter`);
ALTER TABLE `vehicleassignment` ADD INDEX `vehicleassignment_VehicleTypeIDBefore` (`VehicleTypeIDBefore`);
ALTER TABLE `vehiclebrandtype` ADD INDEX `VehicleBrandID` (`VehicleBrandID`);
ALTER TABLE `vehicleservicerequest` ADD INDEX `vehicleservicerequest_UserIDInput` (`UserIDInput`);
ALTER TABLE `vehicleservicerequest` ADD INDEX `vehicleservicerequest_UserIDOwner` (`UserIDOwner`);
ALTER TABLE `vehicleservicerequest` ADD INDEX `vehicleservicerequest_VehicleID` (`VehicleID`);
ALTER TABLE `vehicleservicerequest` ADD INDEX `VehicleServiceRequestStatusID` (`VehicleServiceRequestStatusID`,`UserIDInput`,`VehicleID`,`UserIDOwner`);
ALTER TABLE `vehicleservicerequestassignment` ADD INDEX `vehicleservicerequestassignment_UserID` (`UserID`);
ALTER TABLE `vehicleservicerequestassignment` ADD INDEX `vehicleservicerequestassignment_VehicleServiceRequestStatusID` (`VehicleServiceRequestStatusID`);
ALTER TABLE `vehicleservicerequestassignment` ADD INDEX `VehicleServiceRequestID` (`VehicleServiceRequestID`,`VehicleServiceRequestStatusID`,`UserID`);
ALTER TABLE `vehicleservicerequestdetails` ADD INDEX `vehicleservicerequestdetails_VehicleServiceRequestDetailStatus` (`VehicleServiceRequestDetailStatus`);
ALTER TABLE `vehicleservicerequestdetails` ADD INDEX `vehicleservicerequestdetails_VehicleServiceTypeID` (`VehicleServiceTypeID`);
ALTER TABLE `vehicleservicerequestdetails` ADD INDEX `VehicleServiceRequestID` (`VehicleServiceRequestID`,`VehicleServiceTypeID`,`VehicleServiceRequestDetailStatus`);
ALTER TABLE `vehicleservicerequestdetailsassigntment` ADD INDEX `vehicleservicerequestdetailsassigntment_UserID` (`UserID`);
ALTER TABLE `vehicleservicerequestdetailsassigntment` ADD INDEX `vehicleservicerequestdetailsassigntment_VehSerReqDetailID` (`VehicleServiceRequestDetailID`);
ALTER TABLE `vehicleservicerequestdetailsassigntment` ADD INDEX `vehicleservicerequestdetailsassigntment_VehSerReqStatusID` (`VehicleServiceRequestStatusID`);
ALTER TABLE `vehicleservicerequestdetailsassigntment` ADD INDEX `VehicleServiceRequestID` (`VehicleServiceRequestID`,`VehicleServiceRequestDetailID`,`VehicleServiceRequestStatusID`,`UserID`);
ALTER TABLE `visitplan` ADD INDEX `DivisionID` (`DivisionID`);
ALTER TABLE `visitplan` ADD INDEX `UserIDInput` (`UserIDInput`,`UserIDSales`,`CompanyID`,`CompanyCPID`,`UserIDVisitWith`);
ALTER TABLE `visitplan` ADD INDEX `visitplan_CompanyCPID` (`CompanyCPID`);
ALTER TABLE `visitplan` ADD INDEX `visitplan_CompanyID` (`CompanyID`);
ALTER TABLE `visitplan` ADD INDEX `visitplan_ProjectID` (`ProjectID`);
ALTER TABLE `visitplan` ADD INDEX `visitplan_UserIDSales` (`UserIDSales`);
ALTER TABLE `visitplan` ADD INDEX `visitplan_UserIDVisitWith` (`UserIDVisitWith`);
ALTER TABLE `visitplan` ADD INDEX `visitplan_VisitingPrincipalID` (`VisitingPrincipalID`);
ALTER TABLE `visitplan` ADD INDEX `visitplan_VisitPrincipalCPID` (`VisitPrincipalCPID`);
ALTER TABLE `visitplan` ADD INDEX `VisitPlanStatusID_3` (`VisitPlanStatusID`,`DivisionID`,`UserIDInput`,`UserIDSales`,`CompanyID`,`CompanyCPID`,`UserIDVisitWith`);
ALTER TABLE `visitplanassignment` ADD INDEX `visitplanassignment_UserID` (`UserID`);
ALTER TABLE `visitplanassignment` ADD INDEX `visitplanassignment_VisitPlanStatusID` (`VisitPlanStatusID`);
ALTER TABLE `visitplancompanycpdetail` ADD INDEX `visitplancompanycpdetail_CompanyCPID` (`CompanyCPID`);
ALTER TABLE `visitplancompanycpdetail` ADD INDEX `visitplancompanycpdetail_VisitPlanID` (`VisitPlanID`);
ALTER TABLE `visitplandetail` ADD INDEX `visitplandetail_ActionID` (`ActionID`);
ALTER TABLE `visitplandetail` ADD INDEX `visitplandetail_BarangID` (`BarangID`);
ALTER TABLE `visitplandetail` ADD INDEX `visitplandetail_PrincipalID` (`PrincipalID`);
ALTER TABLE `visitplandetail` ADD INDEX `visitplandetail_ProjectID` (`ProjectID`);
ALTER TABLE `visitplandetailassignment` ADD INDEX `visitplandetailassignment_UserID` (`UserID`);
ALTER TABLE `visitplandetailassignment` ADD INDEX `visitplandetailassignment_VisitPlanDetailID` (`VisitPlanDetailID`);
ALTER TABLE `visitplandetailassignment` ADD INDEX `visitplandetailassignment_VisitPlanStatusID` (`VisitPlanStatusID`);
ALTER TABLE `visitplanfrienddetail` ADD INDEX `visitplanfrienddetail_UserIDVisitWith` (`UserIDVisitWith`);
ALTER TABLE `visitplanfrienddetail` ADD INDEX `visitplanfrienddetail_VisitPlanID` (`VisitPlanID`);
ALTER TABLE `visitplanprincipalvisitdetail` ADD INDEX `visitplanprincipalvisitdetail_VisitingPrincipalCPID` (`VisitingPrincipalCPID`);
ALTER TABLE `visitplanprincipalvisitdetail` ADD INDEX `visitplanprincipalvisitdetail_VisitingPrincipalID` (`VisitingPrincipalID`);
ALTER TABLE `visitplanprincipalvisitdetail` ADD INDEX `visitplanprincipalvisitdetail_VisitPlanID` (`VisitPlanID`);
ALTER TABLE `warehouse` ADD INDEX `warehouse_ParentID` (`ParentID`);
-- `visitplan`.`VisitPlanStatusID` exists on both sides with DIFFERENT columns; dropped and recreated.
--   bukanmain: BTREE [VisitPlanStatusID,DivisionID,UserIDInput,UserIDSales,CompanyID,CompanyCPID,UserIDVisitWith]
--   63       : BTREE [VisitPlanStatusID]
-- This is the ONLY DROP INDEX in the file, and it is NOT a narrowing -- checked on 2026-08-14
-- because it looks like one. bukanmain carries TWO IDENTICAL 7-column composites here,
-- `VisitPlanStatusID` and `VisitPlanStatusID_2`. This statement re-cuts the first to one column;
-- `_2` keeps the composite untouched, and the ADD INDEX four lines below adds `_3`, a third copy
-- of it. Measured on the scratch run: after this script the 7-column composite is present TWICE.
-- Nothing is lost, so criterion 3 ("additive only") holds. Do not "simplify" this by dropping
-- `_2` or `_3` to remove the duplication -- that WOULD be a narrowing.
ALTER TABLE `visitplan` DROP INDEX `VisitPlanStatusID`, ADD INDEX `VisitPlanStatusID` (`VisitPlanStatusID`);

-- ---------------------------------------------------------------------
-- SECTION 8 - Foreign key constraints (659)
-- REMOVED 2026-08-14: `reference`.`PaymentTerm` and `referencehistory`.`PaymentTerm`.
-- 63 constrains both to `quotationpaymentterm`, whose IDs run 1-32. The real bukanmain holds
-- 60, 70, 90, 180 and 360 in these columns -- those are DAY COUNTS, not ids. In
-- `quotationpaymentterm`, 60 and 90 appear only as `TermDay` values (ids 8/17/26 are all
-- '... 60 Days'); 180 and 360 are not even TermDay values, they are 6 and 12 months.
-- 63 violates its own key too -- 1 of 2 `reference` rows and 2 of 4 `referencehistory` rows
-- are orphans there right now, surviving only because the dump loaded with
-- FOREIGN_KEY_CHECKS=0. So the constraint is semantically WRONG, exactly like the
-- salesrebateinvoice one that GH #260 fixed.
-- Applying it would have nulled 69 + 82 = 151 rows of real payment terms on production.
-- The key is dropped from 63 by 2026_08_14_100000_drop_wrong_paymentterm_fks, and neither
-- the constraint nor the cleanup that fed it is generated here any more. The column and its
-- index stay; only the false relationship goes.
--
-- 63 defines 709. The 48 not created here are exactly those whose child table, parent table,
-- or both are among the 55 tables section 2 no longer introduces to production. Verified: NO
-- constraint is lost on a table that DOES exist on bukanmain -- every one of the 48 has at
-- least one endpoint on an omitted table, so there is no silent loss of referential integrity
-- on a live table. The single foreign key that crosses from a production table into a newly
-- created one, quotationdetails.ItemOriginID -> quotationitemorigin, IS created: its parent is
-- one of the four section 2 keeps.
--
-- 8 columns are constrained TWICE, with conflicting referential actions (SET NULL/CASCADE and
-- RESTRICT/RESTRICT). That is faithful to 63, not a mistake here. MEASURED 2026-08-14, not
-- assumed: both constraints ARE created, and RESTRICT wins on both DELETE and UPDATE
-- (ERROR 1451). So the SET NULL/CASCADE twins are dead weight, not a fallback -- deleting a
-- quotation is blocked outright, where anyone reading the SET NULL key would expect its
-- assignments to be detached. Do NOT "tidy" this by dropping the RESTRICT twin: that removes
-- the only thing blocking DELETE FROM quotation, and the surviving SET NULL twin then detaches
-- every assignment row silently. (MySQL documents multiple FKs on one column as undefined, so
-- confirm the same resolution on MariaDB before relying on the blocking behaviour.)
--
-- ⚠ GROUPED ONE ALTER PER TABLE, 2026-08-14. This section used to emit one ALTER per
--   constraint. FOREIGN_KEY_CHECKS is deliberately left ON (see the top of this file), and that
--   forces ALGORITHM=COPY on every ADD CONSTRAINT -- so 659 separate statements meant 659 full
--   table copies across 154 tables: `quotation` copied 19 times, `vehicleassignment` 15,
--   `sampleorder` 14. 52 tables were copied 5+ times, accounting for 410 of the 659.
--   Measured on EMPTY tables: the 19 `quotation` keys took 14,577 ms as 19 statements and
--   781 ms as one -- a ~19x reduction, exactly the number of copies avoided. Section 8 alone
--   was 306 s of a 521 s run with zero rows in the database; on populated production each copy
--   also runs a full foreign-key validation scan, so the saving grows with row count.
--   659 constraints, 154 statements, 154 table copies. Sections 3d, 3e and 4 were already
--   grouped for exactly this reason (see their headers); section 8 was the one that rebuilt
--   the most and had never been given the same treatment.
--   The trade-off, stated plainly: a failure now aborts a whole table's keys rather than one.
--   The server still names the offending constraint, and any failure here means a row survived
--   the sections 5-6 cleanup -- which is a stop-and-look event either way.
-- ---------------------------------------------------------------------
ALTER TABLE `application`
  ADD CONSTRAINT `application_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `application_GroupDivisionID` FOREIGN KEY (`GroupDivisionID`) REFERENCES `groupdivision` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `bank` ADD CONSTRAINT `bank_QuotationPriceDescID` FOREIGN KEY (`QuotationPriceDescID`) REFERENCES `quotationpricedesc` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `bankdivision`
  ADD CONSTRAINT `bankdivision_BankID` FOREIGN KEY (`BankID`) REFERENCES `bank` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `bankdivision_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `barang`
  ADD CONSTRAINT `barang_CategoryID` FOREIGN KEY (`CategoryID`) REFERENCES `category` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `barang_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `barang_SatuanID` FOREIGN KEY (`SatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `barang_TypeID` FOREIGN KEY (`TypeID`) REFERENCES `type` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `baranglist`
  ADD CONSTRAINT `baranglist_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `baranglist_BarangListStatusID` FOREIGN KEY (`BarangListStatusID`) REFERENCES `barangliststatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `baranglist_SampleOrderDetailID` FOREIGN KEY (`SampleOrderDetailID`) REFERENCES `sampleorderdetail` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `baranglist_SatuanID` FOREIGN KEY (`SatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `baranglists`
  ADD CONSTRAINT `baranglists_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `baranglists_SatuanID` FOREIGN KEY (`SatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `barangstockmin`
  ADD CONSTRAINT `barangstockmin_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `barangstockmin_SatuanID` FOREIGN KEY (`SatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `budgetandtarget`
  ADD CONSTRAINT `budgetandtarget_BudgetAndTargetPeriodeID` FOREIGN KEY (`BudgetAndTargetPeriodeID`) REFERENCES `budgetandtargetperiode` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtarget_BudgetAndTargetStatusID` FOREIGN KEY (`BudgetAndTargetStatusID`) REFERENCES `budgetandtargetstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtarget_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtarget_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtarget_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtarget_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtarget_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `budgetandtargetachievements`
  ADD CONSTRAINT `budgetandtargetachievements_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetachievements_BudgetAndTargetPeriodeID` FOREIGN KEY (`BudgetAndTargetPeriodeID`) REFERENCES `budgetandtargetperiode` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetachievements_BudgetAndTargetStatusID` FOREIGN KEY (`BudgetAndTargetStatusID`) REFERENCES `budgetandtargetstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetachievements_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetachievements_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetachievements_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetachievements_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `budgetandtargetassignment`
  ADD CONSTRAINT `budgetandtargetassignment_BudgetAndTargetID` FOREIGN KEY (`BudgetAndTargetID`) REFERENCES `budgetandtarget` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetassignment_BudgetAndTargetStatusID` FOREIGN KEY (`BudgetAndTargetStatusID`) REFERENCES `budgetandtargetstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `budgetandtargetreal`
  ADD CONSTRAINT `budgetandtargetreal_BudgetAndTargetPeriodeID` FOREIGN KEY (`BudgetAndTargetPeriodeID`) REFERENCES `budgetandtargetperiode` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetreal_BudgetAndTargetStatusID` FOREIGN KEY (`BudgetAndTargetStatusID`) REFERENCES `budgetandtargetstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetreal_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetreal_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetreal_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetreal_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `budgetandtargetreal_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `comissionpercentage` ADD CONSTRAINT `comissionpercentage_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `company`
  ADD CONSTRAINT `company_BranchID` FOREIGN KEY (`BranchID`) REFERENCES `branch` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `company_CompanyCategoryID` FOREIGN KEY (`CompanyCategoryID`) REFERENCES `companycategory` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `company_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `company_IndustryID` FOREIGN KEY (`IndustryID`) REFERENCES `industry` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `company_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyaccessothers`
  ADD CONSTRAINT `companyaccessothers_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyaccessothers_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companycategory` ADD CONSTRAINT `companycategory_GroupDivID` FOREIGN KEY (`GroupDivID`) REFERENCES `groupdivision` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companycategorylist`
  ADD CONSTRAINT `companycategorylist_CompanyCategoryID` FOREIGN KEY (`CompanyCategoryID`) REFERENCES `companycategory` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companycategorylist_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companycp`
  ADD CONSTRAINT `companycp_AddressType` FOREIGN KEY (`AddressType`) REFERENCES `addresstype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companycp_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companycpassignment`
  ADD CONSTRAINT `companycpassignment_AddressType` FOREIGN KEY (`AddressType`) REFERENCES `addresstype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companycpassignment_CompanyCPID` FOREIGN KEY (`CompanyCPID`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companycpassignment_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companycpassignment_UsersID` FOREIGN KEY (`UsersID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyhistory`
  ADD CONSTRAINT `companyhistory_BranchID` FOREIGN KEY (`BranchID`) REFERENCES `branch` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyhistory_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyhistory_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyhistory_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyhistory_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyindustry`
  ADD CONSTRAINT `companyindustry_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyindustry_IndustryID` FOREIGN KEY (`IndustryID`) REFERENCES `industry` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyproduct`
  ADD CONSTRAINT `companyproduct_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproduct_CCBarangID` FOREIGN KEY (`CCBarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproduct_CCPriceSatuanID` FOREIGN KEY (`CCPriceSatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproduct_CCPrincipalID` FOREIGN KEY (`CCPrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproduct_CCVolumeSatuanID` FOREIGN KEY (`CCVolumeSatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproduct_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproduct_CompetitorBarangID` FOREIGN KEY (`CompetitorBarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproduct_CompetitorPriceSatuanID` FOREIGN KEY (`CompetitorPriceSatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproduct_CompetitorPrincipalID` FOREIGN KEY (`CompetitorPrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproduct_CompetitorVolumeSatuanID` FOREIGN KEY (`CompetitorVolumeSatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproduct_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyproductapplication`
  ADD CONSTRAINT `companyproductapplication_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductapplication_ProductApplicationID` FOREIGN KEY (`ProductApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyproductassignment`
  ADD CONSTRAINT `companyproductassignment_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductassignment_CCBarangID` FOREIGN KEY (`CCBarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductassignment_CCPriceSatuanID` FOREIGN KEY (`CCPriceSatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductassignment_CCPrincipalID` FOREIGN KEY (`CCPrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductassignment_CCVolumeSatuanID` FOREIGN KEY (`CCVolumeSatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductassignment_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductassignment_CompanyProductID` FOREIGN KEY (`CompanyProductID`) REFERENCES `companyproduct` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductassignment_CompetitorBarangID` FOREIGN KEY (`CompetitorBarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductassignment_CompetitorPriceSatuanID` FOREIGN KEY (`CompetitorPriceSatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductassignment_CompetitorPrincipalID` FOREIGN KEY (`CompetitorPrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductassignment_CompetitorVolumeSatuanID` FOREIGN KEY (`CompetitorVolumeSatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductassignment_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductassignment_UsersID` FOREIGN KEY (`UsersID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyproductcategory`
  ADD CONSTRAINT `companyproductcategory_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductcategory_ProductCategoryID` FOREIGN KEY (`ProductCategoryID`) REFERENCES `category` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyproduction`
  ADD CONSTRAINT `companyproduction_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproduction_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproduction_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproduction_VolumeSatuanID` FOREIGN KEY (`VolumeSatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyproductionassignment`
  ADD CONSTRAINT `companyproductionassignment_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductionassignment_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductionassignment_CompanyProductionID` FOREIGN KEY (`CompanyProductionID`) REFERENCES `companyproduction` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductionassignment_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductionassignment_UsersID` FOREIGN KEY (`UsersID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproductionassignment_VolumeSatuanID` FOREIGN KEY (`VolumeSatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyproject`
  ADD CONSTRAINT `companyproject_CompanyCP` FOREIGN KEY (`CompanyCP`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproject_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproject_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproject_IndustryID` FOREIGN KEY (`IndustryID`) REFERENCES `industry` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproject_ProjectID` FOREIGN KEY (`ProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproject_ProjectPriority` FOREIGN KEY (`ProjectPriority`) REFERENCES `companyprojectpriority` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproject_ProjectStatusID` FOREIGN KEY (`ProjectStatusID`) REFERENCES `companyprojectstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproject_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyproject_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyprojectassignment`
  ADD CONSTRAINT `companyprojectassignment_CompanyProjectDetailCCID` FOREIGN KEY (`CompanyProjectDetailCCID`) REFERENCES `companyprojectdetailcc` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectassignment_CompanyProjectDetailID` FOREIGN KEY (`CompanyProjectDetailID`) REFERENCES `companyprojectdetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectassignment_CompanyProjectID` FOREIGN KEY (`CompanyProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectassignment_ProjectStatusID` FOREIGN KEY (`ProjectStatusID`) REFERENCES `companyprojectstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectassignment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyprojectdetailcc`
  ADD CONSTRAINT `companyprojectdetailcc_CompanyProjectID` FOREIGN KEY (`CompanyProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcc_DetailID` FOREIGN KEY (`DetailID`) REFERENCES `companyprojectdetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcc_ItemReasonID` FOREIGN KEY (`ItemReasonID`) REFERENCES `companyprojectdetailstatusreason` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcc_ItemStatusID` FOREIGN KEY (`ItemStatusID`) REFERENCES `companyprojectdetailstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcc_PriceTypeID` FOREIGN KEY (`PriceTypeID`) REFERENCES `pricetype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcc_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcc_ProductID` FOREIGN KEY (`ProductID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcc_ProjectStatusID` FOREIGN KEY (`ProjectStatusID`) REFERENCES `companyprojectstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcc_QtTypeID` FOREIGN KEY (`QtTypeID`) REFERENCES `quantitytype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcc_SatuanID` FOREIGN KEY (`SatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyprojectdetailccassignment`
  ADD CONSTRAINT `companyprojectdetailccassignment_CompanyProjectID` FOREIGN KEY (`CompanyProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailccassignment_DetailCCID` FOREIGN KEY (`DetailCCID`) REFERENCES `companyprojectdetailcc` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailccassignment_DetailID` FOREIGN KEY (`DetailID`) REFERENCES `companyprojectdetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailccassignment_PriceTypeID` FOREIGN KEY (`PriceTypeID`) REFERENCES `pricetype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailccassignment_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailccassignment_ProductID` FOREIGN KEY (`ProductID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailccassignment_QtTypeID` FOREIGN KEY (`QtTypeID`) REFERENCES `quantitytype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailccassignment_SatuanID` FOREIGN KEY (`SatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailccassignment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyprojectdetailcomp`
  ADD CONSTRAINT `companyprojectdetailcomp_CompanyProjectID` FOREIGN KEY (`CompanyProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcomp_DetailID` FOREIGN KEY (`DetailID`) REFERENCES `companyprojectdetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcomp_PriceTypeIDComp` FOREIGN KEY (`PriceTypeIDComp`) REFERENCES `pricetype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcomp_PrincipalIDComp` FOREIGN KEY (`PrincipalIDComp`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcomp_ProductIDComp` FOREIGN KEY (`ProductIDComp`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcomp_QtTypeIDComp` FOREIGN KEY (`QtTypeIDComp`) REFERENCES `quantitytype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcomp_SatuanIDComp` FOREIGN KEY (`SatuanIDComp`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyprojectdetailcompassignment`
  ADD CONSTRAINT `companyprojectdetailcompassignment_CompanyProjectIDID` FOREIGN KEY (`CompanyProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcompassignment_DetailCompID` FOREIGN KEY (`DetailCompID`) REFERENCES `companyprojectdetailcomp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcompassignment_DetailID` FOREIGN KEY (`DetailID`) REFERENCES `companyprojectdetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcompassignment_PriceTypeIDComp` FOREIGN KEY (`PriceTypeIDComp`) REFERENCES `pricetype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcompassignment_PrincipalIDComp` FOREIGN KEY (`PrincipalIDComp`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcompassignment_ProductIDComp` FOREIGN KEY (`ProductIDComp`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcompassignment_QtTypeIDComp` FOREIGN KEY (`QtTypeIDComp`) REFERENCES `quantitytype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcompassignment_SatuanIDComp` FOREIGN KEY (`SatuanIDComp`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailcompassignment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyprojectdetails`
  ADD CONSTRAINT `companyprojectdetails_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetails_CompanyProjectID` FOREIGN KEY (`CompanyProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetails_OpportunityGroupID` FOREIGN KEY (`OpportunityGroupID`) REFERENCES `companyprojectopportunitygroup` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetails_ProjectStatusID` FOREIGN KEY (`ProjectStatusID`) REFERENCES `companyprojectstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyprojectdetailsassignment`
  ADD CONSTRAINT `companyprojectdetailsassignment_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailsassignment_CompanyProjectID` FOREIGN KEY (`CompanyProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailsassignment_DetailID` FOREIGN KEY (`DetailID`) REFERENCES `companyprojectdetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailsassignment_OpportunityGroupID` FOREIGN KEY (`OpportunityGroupID`) REFERENCES `companyprojectopportunitygroup` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailsassignment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyprojectdetailstatusassignment`
  ADD CONSTRAINT `companyprojectdetailstatusassignment_CompanyProjectID` FOREIGN KEY (`CompanyProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailstatusassignment_DetailCCID` FOREIGN KEY (`DetailCCID`) REFERENCES `companyprojectdetailcc` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailstatusassignment_DetailID` FOREIGN KEY (`DetailID`) REFERENCES `companyprojectdetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailstatusassignment_ItemReasonID` FOREIGN KEY (`ItemReasonID`) REFERENCES `companyprojectdetailstatusreason` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailstatusassignment_ItemStatusID` FOREIGN KEY (`ItemStatusID`) REFERENCES `companyprojectdetailstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailstatusassignment_ProjectStatusID` FOREIGN KEY (`ProjectStatusID`) REFERENCES `companyprojectstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectdetailstatusassignment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyprojectdetailstatusreason` ADD CONSTRAINT `companyprojectdetailstatusreason_StatusID` FOREIGN KEY (`StatusID`) REFERENCES `companyprojectdetailstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `companyprojectheaderassignment`
  ADD CONSTRAINT `companyprojectheaderassignment_CompanyCP` FOREIGN KEY (`CompanyCP`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectheaderassignment_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectheaderassignment_CompanyProjectID` FOREIGN KEY (`CompanyProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectheaderassignment_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectheaderassignment_IndustryID` FOREIGN KEY (`IndustryID`) REFERENCES `industry` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectheaderassignment_ProjectID` FOREIGN KEY (`ProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectheaderassignment_ProjectPriority` FOREIGN KEY (`ProjectPriority`) REFERENCES `companyprojectpriority` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectheaderassignment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `companyprojectheaderassignment_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complain`
  ADD CONSTRAINT `complain_CompanyCPID` FOREIGN KEY (`CompanyCPID`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complain_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complain_ComplainReasonID` FOREIGN KEY (`ComplainReasonID`) REFERENCES `complainreason` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complain_ComplainStatusID` FOREIGN KEY (`ComplainStatusID`) REFERENCES `complainstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complain_ComplainTypeID` FOREIGN KEY (`ComplainTypeID`) REFERENCES `complaintype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complain_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complain_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complain_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complainassignment`
  ADD CONSTRAINT `complainassignment_ComplainID` FOREIGN KEY (`ComplainID`) REFERENCES `complain` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainassignment_ComplainStatusID` FOREIGN KEY (`ComplainStatusID`) REFERENCES `complainstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complaindetails`
  ADD CONSTRAINT `complaindetails_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetails_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetails_ComplainDetailsStatusID` FOREIGN KEY (`ComplainDetailsStatusID`) REFERENCES `complaindetailsstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetails_ComplainID` FOREIGN KEY (`ComplainID`) REFERENCES `complain` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetails_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetails_SatuanComplainQuantityID` FOREIGN KEY (`SatuanComplainQuantityID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetails_SatuanPackingID` FOREIGN KEY (`SatuanPackingID`) REFERENCES `quotationpack` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetails_SatuanUnitPriceUSD` FOREIGN KEY (`SatuanUnitPriceUSD`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complaindetailsaction`
  ADD CONSTRAINT `complaindetailsaction_ComplainDetailsID` FOREIGN KEY (`ComplainDetailsID`) REFERENCES `complaindetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetailsaction_ComplainDetailsStatusID` FOREIGN KEY (`ComplainDetailsStatusID`) REFERENCES `complaindetailsstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetailsaction_ComplainID` FOREIGN KEY (`ComplainID`) REFERENCES `complain` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetailsaction_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complaindetailsactionassignment`
  ADD CONSTRAINT `complaindetailsactionassignment_ComplainDetailsActionID` FOREIGN KEY (`ComplainDetailsActionID`) REFERENCES `complaindetailsaction` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetailsactionassignment_ComplainDetailsID` FOREIGN KEY (`ComplainDetailsID`) REFERENCES `complaindetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetailsactionassignment_ComplainDetailsStatusID` FOREIGN KEY (`ComplainDetailsStatusID`) REFERENCES `complaindetailsstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetailsactionassignment_ComplainID` FOREIGN KEY (`ComplainID`) REFERENCES `complain` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetailsactionassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complaindetailsassignment`
  ADD CONSTRAINT `complaindetailsassignment_ComplainDetailsID` FOREIGN KEY (`ComplainDetailsID`) REFERENCES `complaindetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetailsassignment_ComplainDetailsStatusID` FOREIGN KEY (`ComplainDetailsStatusID`) REFERENCES `complaindetailsstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetailsassignment_ComplainID` FOREIGN KEY (`ComplainID`) REFERENCES `complain` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaindetailsassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complainitem`
  ADD CONSTRAINT `complainitem_ComplainStatusID` FOREIGN KEY (`ComplainStatusID`) REFERENCES `complainitemstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitem_ComplainTypeID` FOREIGN KEY (`ComplainTypeID`) REFERENCES `complainitemtype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitem_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitem_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complainitemassignment`
  ADD CONSTRAINT `complainitemassignment_ComplainItemID` FOREIGN KEY (`ComplainItemID`) REFERENCES `complainitem` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemassignment_ComplainItemStatusID` FOREIGN KEY (`ComplainItemStatusID`) REFERENCES `complainitemstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemassignment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complainitemdetails`
  ADD CONSTRAINT `complainitemdetails_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetails_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetails_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetails_ComplainDetailStatusID` FOREIGN KEY (`ComplainDetailStatusID`) REFERENCES `complaindetailsstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetails_ComplainItemID` FOREIGN KEY (`ComplainItemID`) REFERENCES `complainitem` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetails_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetails_IndustryID` FOREIGN KEY (`IndustryID`) REFERENCES `industry` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetails_PackingMonth` FOREIGN KEY (`PackingMonth`) REFERENCES `packing` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetails_PackingYear` FOREIGN KEY (`PackingYear`) REFERENCES `packing` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complainitemdetailsaction`
  ADD CONSTRAINT `complainitemdetailsaction_ComplainID` FOREIGN KEY (`ComplainID`) REFERENCES `complainitem` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetailsaction_ComplainStatusID` FOREIGN KEY (`ComplainStatusID`) REFERENCES `complainitemstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetailsaction_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complainitemdetailsactionassignment`
  ADD CONSTRAINT `complainitemdetailsactionassignment_ComplainItemID` FOREIGN KEY (`ComplainItemID`) REFERENCES `complainitem` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetailsactionassignment_ComplainItemStatusID` FOREIGN KEY (`ComplainItemStatusID`) REFERENCES `complainitemstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetailsactionassignment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complainitemdetailslot`
  ADD CONSTRAINT `complainitemdetailslot_ComplainItemDetailsID` FOREIGN KEY (`ComplainItemDetailsID`) REFERENCES `complainitemdetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetailslot_ComplainItemID` FOREIGN KEY (`ComplainItemID`) REFERENCES `complainitem` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetailslot_PackagingID` FOREIGN KEY (`PackagingID`) REFERENCES `packing` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complainitemdetailslotassignment`
  ADD CONSTRAINT `complainitemdetailslotassignment_ComplainItemDetailsID` FOREIGN KEY (`ComplainItemDetailsID`) REFERENCES `complainitemdetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetailslotassignment_ComplainItemDetailsLotID` FOREIGN KEY (`ComplainItemDetailsLotID`) REFERENCES `complainitemdetailslot` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetailslotassignment_ComplainItemID` FOREIGN KEY (`ComplainItemID`) REFERENCES `complainitem` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complainitemdetailslotassignment_PackagingID` FOREIGN KEY (`PackagingID`) REFERENCES `packing` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complaintosupplier`
  ADD CONSTRAINT `complaintosupplier_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplier_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplier_ComplainItemTypeID` FOREIGN KEY (`ComplainItemTypeID`) REFERENCES `complaintosuppliertype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplier_ComplainStatusID` FOREIGN KEY (`ComplainStatusID`) REFERENCES `complaintosupplierstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplier_ComplainTypeID` FOREIGN KEY (`ComplainTypeID`) REFERENCES `complaintype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplier_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplier_IndustryID` FOREIGN KEY (`IndustryID`) REFERENCES `industry` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplier_PackingMonth` FOREIGN KEY (`PackingMonth`) REFERENCES `packing` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplier_PackingYear` FOREIGN KEY (`PackingYear`) REFERENCES `packing` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplier_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplier_ProductID` FOREIGN KEY (`ProductID`) REFERENCES `product` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplier_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplier_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complaintosupplierassignment`
  ADD CONSTRAINT `complaintosupplierassignment_ComplainID` FOREIGN KEY (`ComplainID`) REFERENCES `complaintosupplier` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplierassignment_ComplainStatusID` FOREIGN KEY (`ComplainStatusID`) REFERENCES `complaintosupplierstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplierassignment_DepartmentID` FOREIGN KEY (`DepartmentID`) REFERENCES `department` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplierassignment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complaintosupplierdetailsaction`
  ADD CONSTRAINT `complaintosupplierdetailsaction_ComplainID` FOREIGN KEY (`ComplainID`) REFERENCES `complaintosupplier` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplierdetailsaction_ComplainStatusID` FOREIGN KEY (`ComplainStatusID`) REFERENCES `complaintosupplierstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplierdetailsaction_DepartementID` FOREIGN KEY (`DepartementID`) REFERENCES `department` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplierdetailsaction_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `complaintosupplierdetailsactionassignment`
  ADD CONSTRAINT `complaintosupplierdetailsactionassignment_ComplainID` FOREIGN KEY (`ComplainID`) REFERENCES `complaintosupplier` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplierdetailsactionassignment_ComplainStatusID` FOREIGN KEY (`ComplainStatusID`) REFERENCES `complaintosupplierstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplierdetailsactionassignment_DepartmentID` FOREIGN KEY (`DepartmentID`) REFERENCES `department` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `complaintosupplierdetailsactionassignment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `division` ADD CONSTRAINT `division_GroupDivisionID` FOREIGN KEY (`GroupDivisionID`) REFERENCES `groupdivision` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `documentgroupdivision`
  ADD CONSTRAINT `documentgroupdivision_DocID` FOREIGN KEY (`DocID`) REFERENCES `documentupload` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `documentgroupdivision_GroupDivID` FOREIGN KEY (`GroupDivID`) REFERENCES `groupdivision` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `documentupload`
  ADD CONSTRAINT `documentupload_DocumentCategoryID` FOREIGN KEY (`DocumentCategoryID`) REFERENCES `documentcategory` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `documentupload_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `documentuploadinternal` ADD CONSTRAINT `documentuploadinternal_DocumentCategoryID` FOREIGN KEY (`DocumentCategoryID`) REFERENCES `documentcategory` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `izin`
  ADD CONSTRAINT `izin_IzinStatusID` FOREIGN KEY (`IzinStatusID`) REFERENCES `izinstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `izin_IzinTypeID` FOREIGN KEY (`IzinTypeID`) REFERENCES `izintype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `izin_IzinTypeStatusID` FOREIGN KEY (`IzinTypeStatusID`) REFERENCES `izintypestatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `izin_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `izin_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `izinassignment`
  ADD CONSTRAINT `izinassignment_IzinID` FOREIGN KEY (`IzinID`) REFERENCES `izin` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `izinassignment_IzinStatusID` FOREIGN KEY (`IzinStatusID`) REFERENCES `izinstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `izinassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `izintypestatus` ADD CONSTRAINT `izintypestatus_IzinTypeID` FOREIGN KEY (`IzinTypeID`) REFERENCES `izintype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `labworkrequest`
  ADD CONSTRAINT `labworkrequest_CompanyCPID` FOREIGN KEY (`CompanyCPID`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequest_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequest_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequest_IndustryID` FOREIGN KEY (`IndustryID`) REFERENCES `industry` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequest_LabWorkRequestFeedbackStatusID` FOREIGN KEY (`LabWorkRequestFeedbackStatusID`) REFERENCES `labworkrequestfeedbackstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequest_LabWorkRequestStatusID` FOREIGN KEY (`LabWorkRequestStatusID`) REFERENCES `labworkrequeststatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequest_ProjectID` FOREIGN KEY (`ProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequest_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequest_UserIDProjectInitiator` FOREIGN KEY (`UserIDProjectInitiator`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequest_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `labworkrequestassignment`
  ADD CONSTRAINT `labworkrequestassignment_LabWorkRequestID` FOREIGN KEY (`LabWorkRequestID`) REFERENCES `labworkrequest` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequestassignment_LabWorkRequestStatusID` FOREIGN KEY (`LabWorkRequestStatusID`) REFERENCES `labworkrequeststatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequestassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `labworkrequestdetails`
  ADD CONSTRAINT `labworkrequestdetails_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequestdetails_LabWorkRequestDetailStatusID` FOREIGN KEY (`LabWorkRequestDetailStatusID`) REFERENCES `labworkrequestdetailstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequestdetails_LabWorkRequestID` FOREIGN KEY (`LabWorkRequestID`) REFERENCES `labworkrequest` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequestdetails_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequestdetails_ProjectID` FOREIGN KEY (`ProjectID`) REFERENCES `companyprojectdetailcc` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequestdetails_ProjectIDComp` FOREIGN KEY (`ProjectIDComp`) REFERENCES `companyprojectdetailcomp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequestdetails_SatuanIDUnitPrice` FOREIGN KEY (`SatuanIDUnitPrice`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequestdetails_SatuanIDVolume` FOREIGN KEY (`SatuanIDVolume`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequestdetails_TypeID` FOREIGN KEY (`TypeID`) REFERENCES `type` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `labworkrequestdetailsassignment`
  ADD CONSTRAINT `labworkrequestdetailsassignment_LabWorkRequestDetailID` FOREIGN KEY (`LabWorkRequestDetailID`) REFERENCES `labworkrequestdetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequestdetailsassignment_LabWorkRequestDetailStatusID` FOREIGN KEY (`LabWorkRequestDetailStatusID`) REFERENCES `labworkrequestdetailstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequestdetailsassignment_LabWorkRequestID` FOREIGN KEY (`LabWorkRequestID`) REFERENCES `labworkrequest` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `labworkrequestdetailsassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `labworkrequestlink` ADD CONSTRAINT `labworkrequestlink_LabWorkRequestID` FOREIGN KEY (`LabWorkRequestID`) REFERENCES `labworkrequest` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `lembur`
  ADD CONSTRAINT `lembur_LemburStatusID` FOREIGN KEY (`LemburStatusID`) REFERENCES `lemburstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `lembur_LemburTypeID` FOREIGN KEY (`LemburTypeID`) REFERENCES `lemburtype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `lembur_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `lembur_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `lemburassignment`
  ADD CONSTRAINT `lemburassignment_LemburID` FOREIGN KEY (`LemburID`) REFERENCES `lembur` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `lemburassignment_LemburStatusID` FOREIGN KEY (`LemburStatusID`) REFERENCES `lemburstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `lemburassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `menu` ADD CONSTRAINT `menu_ParentID` FOREIGN KEY (`ParentID`) REFERENCES `menu` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `news` ADD CONSTRAINT `news_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `onleave`
  ADD CONSTRAINT `onleave_OnLeaveLimitID` FOREIGN KEY (`OnLeaveLimitID`) REFERENCES `onleavelimit` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `onleave_OnLeaveStatusID` FOREIGN KEY (`OnLeaveStatusID`) REFERENCES `onleavestatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `onleave_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `onleave_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `onleave_UserPengganti1` FOREIGN KEY (`UserPengganti1`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `onleave_UserPengganti2` FOREIGN KEY (`UserPengganti2`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `onleaveadditional`
  ADD CONSTRAINT `onleaveadditional_OnLeaveLimitID` FOREIGN KEY (`OnLeaveLimitID`) REFERENCES `onleavelimit` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `onleaveadditional_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `onleaveadditional_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `onleaveadditionalassignment`
  ADD CONSTRAINT `onleaveadditionalassignment_OnLeaveAdditionalID` FOREIGN KEY (`OnLeaveAdditionalID`) REFERENCES `onleaveadditional` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `onleaveadditionalassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `onleaveassignment`
  ADD CONSTRAINT `onleaveassignment_OnLeaveID` FOREIGN KEY (`OnLeaveID`) REFERENCES `onleave` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `onleaveassignment_OnLeaveStatusID` FOREIGN KEY (`OnLeaveStatusID`) REFERENCES `onleavestatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `onleaveassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `packing` ADD CONSTRAINT `packing_SatuanID` FOREIGN KEY (`SatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `potentialsales`
  ADD CONSTRAINT `potentialsales_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `potentialsales_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `potentialsales_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `potentialsaleshistory`
  ADD CONSTRAINT `potentialsaleshistory_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `potentialsaleshistory_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `potentialsaleshistory_PotentialSalesID` FOREIGN KEY (`PotentialSalesID`) REFERENCES `potentialsales` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `potentialsaleshistory_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `potentialsaleshistory_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `principalcp`
  ADD CONSTRAINT `principalcp_AddressType` FOREIGN KEY (`AddressType`) REFERENCES `addresstype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `principalcp_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `principalcpassignment`
  ADD CONSTRAINT `principalcpassignment_AddressType` FOREIGN KEY (`AddressType`) REFERENCES `addresstype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `principalcpassignment_PrincipalCPID` FOREIGN KEY (`PrincipalCPID`) REFERENCES `principalcp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `principalcpassignment_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `principalcpassignment_UsersID` FOREIGN KEY (`UsersID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `principalfaq` ADD CONSTRAINT `principalfaq_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `principalfaqhistory`
  ADD CONSTRAINT `principalfaqhistory_PrincipalFAQID` FOREIGN KEY (`PrincipalFAQID`) REFERENCES `principalfaq` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `principalfaqhistory_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `printeditemfulfillment` ADD CONSTRAINT `printeditemfulfillment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `product`
  ADD CONSTRAINT `product_ClassID` FOREIGN KEY (`ClassID`) REFERENCES `class` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `product_PackingID` FOREIGN KEY (`PackingID`) REFERENCES `packing` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `product_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `productapplication`
  ADD CONSTRAINT `productapplication_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `productapplication_ProductID` FOREIGN KEY (`ProductID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `productapplication_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `productcategory`
  ADD CONSTRAINT `productcategory_CategoryID` FOREIGN KEY (`CategoryID`) REFERENCES `category` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `productcategory_ProductID` FOREIGN KEY (`ProductID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `productcategory_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `proposedcreditceiling`
  ADD CONSTRAINT `proposedcreditceiling_CCStatusID` FOREIGN KEY (`CCStatusID`) REFERENCES `creditceilingstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `proposedcreditceiling_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `proposedcreditceiling_JustificationID` FOREIGN KEY (`JustificationID`) REFERENCES `justification` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `proposedcreditceiling_QuotationPaymentTermApprovedID` FOREIGN KEY (`QuotationPaymentTermApprovedID`) REFERENCES `quotationpaymentterm` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `proposedcreditceiling_QuotationPaymentTermID` FOREIGN KEY (`QuotationPaymentTermID`) REFERENCES `quotationpaymentterm` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `proposedcreditceiling_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `proposedcreditceilinghistory`
  ADD CONSTRAINT `proposedcreditceilinghistory_CCStatusID` FOREIGN KEY (`CCStatusID`) REFERENCES `creditceilingstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `proposedcreditceilinghistory_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `proposedcreditceilinghistory_JustificationID` FOREIGN KEY (`JustificationID`) REFERENCES `justification` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `proposedcreditceilinghistory_ProposedCCID` FOREIGN KEY (`ProposedCCID`) REFERENCES `proposedcreditceiling` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `proposedcreditceilinghistory_QuotationPaymentTermApprovedID` FOREIGN KEY (`QuotationPaymentTermApprovedID`) REFERENCES `quotationpaymentterm` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `proposedcreditceilinghistory_QuotationPaymentTermID` FOREIGN KEY (`QuotationPaymentTermID`) REFERENCES `quotationpaymentterm` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `proposedcreditceilinghistory_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `purchaseorder`
  ADD CONSTRAINT `purchaseorder_PurchaseOrderStatusID` FOREIGN KEY (`PurchaseOrderStatusID`) REFERENCES `purchaseorderstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `purchaseorder_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `purchaseorderassignment`
  ADD CONSTRAINT `purchaseorderassignment_PurchaseOrderID` FOREIGN KEY (`PurchaseOrderID`) REFERENCES `purchaseorder` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `purchaseorderassignment_PurchaseOrderStatusID` FOREIGN KEY (`PurchaseOrderStatusID`) REFERENCES `purchaseorderstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `purchaseorderassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `purchaseorderdetails`
  ADD CONSTRAINT `purchaseorderdetails_PackingID` FOREIGN KEY (`PackingID`) REFERENCES `packing` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `purchaseorderdetails_PurchaseOrderDetailStatusID` FOREIGN KEY (`PurchaseOrderDetailStatusID`) REFERENCES `purchaseorderstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `purchaseorderdetails_PurchaseOrderID` FOREIGN KEY (`PurchaseOrderID`) REFERENCES `purchaseorder` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `purchaseorderdetails_SatuanID` FOREIGN KEY (`SatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `purchaseorderdetails_SatuanOrderQtyID` FOREIGN KEY (`SatuanOrderQtyID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `purchaseorderdetailsassignment`
  ADD CONSTRAINT `purchaseorderdetailsassignment_PurchaseOrderDetailID` FOREIGN KEY (`PurchaseOrderDetailID`) REFERENCES `purchaseorderdetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `purchaseorderdetailsassignment_PurchaseOrderID` FOREIGN KEY (`PurchaseOrderID`) REFERENCES `purchaseorder` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `purchaseorderdetailsassignment_PurchaseOrderStatusID` FOREIGN KEY (`PurchaseOrderStatusID`) REFERENCES `purchaseorderstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `purchaseorderdetailsassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `purchaseorderhargajual` ADD CONSTRAINT `purchaseorderhargajual_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `quotation`
  ADD CONSTRAINT `quotation_CompanyCPID` FOREIGN KEY (`CompanyCPID`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_DeliveryAddressID` FOREIGN KEY (`DeliveryAddressID`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_InvoiceAddressID` FOREIGN KEY (`InvoiceAddressID`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_QuotationDeliveryTimeID` FOREIGN KEY (`QuotationDeliveryTimeID`) REFERENCES `quotationdeliverytime` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_QuotationFeedbackStatusID` FOREIGN KEY (`QuotationFeedbackStatusID`) REFERENCES `quotationfeedbackstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_QuotationPaymentTermID` FOREIGN KEY (`QuotationPaymentTermID`) REFERENCES `quotationpaymentterm` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_QuotationPriceDescID` FOREIGN KEY (`QuotationPriceDescID`) REFERENCES `quotationpricedesc` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_QuotationSalesTermID` FOREIGN KEY (`QuotationSalesTermID`) REFERENCES `quotationsalesterm` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_QuotationStatusID` FOREIGN KEY (`QuotationStatusID`) REFERENCES `quotationstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_QuotationStockAvailibilityID` FOREIGN KEY (`QuotationStockAvailibilityID`) REFERENCES `quotationstockavailability` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_QuotationSubjectID` FOREIGN KEY (`QuotationSubjectID`) REFERENCES `quotationsubject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_QuotationTitleID` FOREIGN KEY (`QuotationTitleID`) REFERENCES `quotationtitle` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_QuotationTypeID` FOREIGN KEY (`QuotationTypeID`) REFERENCES `quotationtype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_QuotationValidityID` FOREIGN KEY (`QuotationValidityID`) REFERENCES `quotationvalidity` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_ReferenceQuotationID` FOREIGN KEY (`ReferenceQuotationID`) REFERENCES `quotation` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotation_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `quotationassignment`
  ADD CONSTRAINT `qta_fk_QuotationID` FOREIGN KEY (`QuotationID`) REFERENCES `quotation` (`ID`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `qta_fk_QuotationStatusID` FOREIGN KEY (`QuotationStatusID`) REFERENCES `quotationstatus` (`ID`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `qta_fk_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `quotationassignment_QuotationID` FOREIGN KEY (`QuotationID`) REFERENCES `quotation` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationassignment_QuotationStatusID` FOREIGN KEY (`QuotationStatusID`) REFERENCES `quotationstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `quotationdetails`
  ADD CONSTRAINT `quotationdetails_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationdetails_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationdetails_ItemOriginID` FOREIGN KEY (`ItemOriginID`) REFERENCES `quotationitemorigin` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationdetails_PackingID` FOREIGN KEY (`PackingID`) REFERENCES `packing` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationdetails_ProjectID` FOREIGN KEY (`ProjectID`) REFERENCES `companyprojectdetailcc` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationdetails_QuotationDetailStatusID` FOREIGN KEY (`QuotationDetailStatusID`) REFERENCES `quotationdetailstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationdetails_QuotationID` FOREIGN KEY (`QuotationID`) REFERENCES `quotation` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationdetails_QuotationPackID` FOREIGN KEY (`QuotationPackID`) REFERENCES `quotationpack` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationdetails_SatuanID` FOREIGN KEY (`SatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationdetails_SatuanOrderQty` FOREIGN KEY (`SatuanOrderQty`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `quotationdetailsassignment`
  ADD CONSTRAINT `qda_fk_QuotationDetailID` FOREIGN KEY (`QuotationDetailID`) REFERENCES `quotationdetails` (`ID`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `qda_fk_QuotationDetailStatusID` FOREIGN KEY (`QuotationDetailStatusID`) REFERENCES `quotationdetailstatus` (`ID`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `qda_fk_QuotationID` FOREIGN KEY (`QuotationID`) REFERENCES `quotation` (`ID`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `qda_fk_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `quotationdetailsassignment_QuotationDetailID` FOREIGN KEY (`QuotationDetailID`) REFERENCES `quotationdetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationdetailsassignment_QuotationDetailStatusID` FOREIGN KEY (`QuotationDetailStatusID`) REFERENCES `quotationdetailstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationdetailsassignment_QuotationID` FOREIGN KEY (`QuotationID`) REFERENCES `quotation` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `quotationdetailsassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `quotationlink`
  ADD CONSTRAINT `ql_fk_QuotationID` FOREIGN KEY (`QuotationID`) REFERENCES `quotation` (`ID`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `quotationlink_QuotationID` FOREIGN KEY (`QuotationID`) REFERENCES `quotation` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `reference` ADD CONSTRAINT `reference_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `referencehistory`
  ADD CONSTRAINT `referencehistory_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `referencehistory_ReferenceID` FOREIGN KEY (`ReferenceID`) REFERENCES `reference` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `referencehistory_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `relabelhistory` ADD CONSTRAINT `relabelhistory_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `rolegadget`
  ADD CONSTRAINT `rolegadget_GadgetID` FOREIGN KEY (`GadgetID`) REFERENCES `gadget` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `rolegadget_RoleID` FOREIGN KEY (`RoleID`) REFERENCES `role` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `rolemenu`
  ADD CONSTRAINT `rolemenu_MenuID` FOREIGN KEY (`MenuID`) REFERENCES `menu` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `rolemenu_RoleID` FOREIGN KEY (`RoleID`) REFERENCES `role` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `salesrebate`
  ADD CONSTRAINT `salesrebate_CCPaymentTerm` FOREIGN KEY (`CCPaymentTerm`) REFERENCES `quotationpaymentterm` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebate_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebate_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebate_IndustryID` FOREIGN KEY (`IndustryID`) REFERENCES `industry` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebate_ReferenceRebateID` FOREIGN KEY (`ReferenceRebateID`) REFERENCES `salesrebate` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebate_SalesRebateStatusID` FOREIGN KEY (`SalesRebateStatusID`) REFERENCES `salesrebatestatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebate_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebate_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `salesrebateassignment`
  ADD CONSTRAINT `salesrebateassignment_SalesRebateID` FOREIGN KEY (`SalesRebateID`) REFERENCES `salesrebate` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebateassignment_SalesRebateStatusID` FOREIGN KEY (`SalesRebateStatusID`) REFERENCES `salesrebatestatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebateassignment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `salesrebatedetail`
  ADD CONSTRAINT `salesrebatedetail_CompanyCPID` FOREIGN KEY (`CompanyCPID`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebatedetail_SalesRebateID` FOREIGN KEY (`SalesRebateID`) REFERENCES `salesrebate` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `salesrebateinvoice`
  ADD CONSTRAINT `salesrebateinvoice_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebateinvoice_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebateinvoice_IndustryID` FOREIGN KEY (`IndustryID`) REFERENCES `industry` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebateinvoice_SalesRebateID` FOREIGN KEY (`SalesRebateID`) REFERENCES `salesrebate` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebateinvoice_SalesRebateInvoiceStatusID` FOREIGN KEY (`SalesRebateInvoiceStatusID`) REFERENCES `salesrebateinvoicedetailstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebateinvoice_UserInput` FOREIGN KEY (`UserInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `salesrebateinvoiceassignment`
  ADD CONSTRAINT `salesrebateinvoiceassignment_SalesRebateInvoiceID` FOREIGN KEY (`SalesRebateInvoiceID`) REFERENCES `salesrebateinvoice` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebateinvoiceassignment_SalesRebateInvoiceStatusID` FOREIGN KEY (`SalesRebateInvoiceStatusID`) REFERENCES `salesrebateinvoicedetailstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebateinvoiceassignment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `salesrebateinvoicedetail`
  ADD CONSTRAINT `salesrebateinvoicedetail_PaymentCPID` FOREIGN KEY (`PaymentCPID`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebateinvoicedetail_SalesRebateID` FOREIGN KEY (`SalesRebateID`) REFERENCES `salesrebate` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebateinvoicedetail_SalesRebateInvoiceDetailStatusID` FOREIGN KEY (`SalesRebateInvoiceDetailStatusID`) REFERENCES `salesrebateinvoicedetailstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `salesrebateinvoicedetail_SalesRebateInvoiceID` FOREIGN KEY (`SalesRebateInvoiceID`) REFERENCES `salesrebateinvoice` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `salesrebateinvoicepaymentdetail` ADD CONSTRAINT `salesrebateinvoicepaymentdetail_SalesRebateInvoiceDetailID` FOREIGN KEY (`SalesRebateInvoiceDetailID`) REFERENCES `salesrebateinvoicedetail` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `sampleorder`
  ADD CONSTRAINT `sampleorder_CompanyCPID` FOREIGN KEY (`CompanyCPID`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorder_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorder_DeliveryID` FOREIGN KEY (`DeliveryID`) REFERENCES `delivery` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorder_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorder_IndustryID` FOREIGN KEY (`IndustryID`) REFERENCES `industry` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorder_LocationID` FOREIGN KEY (`LocationID`) REFERENCES `location` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorder_PriorityID` FOREIGN KEY (`PriorityID`) REFERENCES `priority` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorder_ProjectID` FOREIGN KEY (`ProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorder_ReferenceSOID` FOREIGN KEY (`ReferenceSOID`) REFERENCES `sampleorder` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorder_SampleOrderByID` FOREIGN KEY (`SampleOrderByID`) REFERENCES `sampleorderby` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorder_SampleOrderFeedbackStatusID` FOREIGN KEY (`SampleOrderFeedbackStatusID`) REFERENCES `sampleorderfeedbackstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorder_SampleOrderStatusID` FOREIGN KEY (`SampleOrderStatusID`) REFERENCES `sampleorderstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorder_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorder_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `sampleorderassignment`
  ADD CONSTRAINT `sampleorderassignment_SampleOrderID` FOREIGN KEY (`SampleOrderID`) REFERENCES `sampleorder` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorderassignment_SampleOrderStatusID` FOREIGN KEY (`SampleOrderStatusID`) REFERENCES `sampleorderstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorderassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `sampleorderdetail`
  ADD CONSTRAINT `sampleorderdetail_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorderdetail_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorderdetail_BarangListID` FOREIGN KEY (`BarangListID`) REFERENCES `baranglists` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorderdetail_BarangListIDRequest` FOREIGN KEY (`BarangListIDRequest`) REFERENCES `baranglists` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorderdetail_ProjectID` FOREIGN KEY (`ProjectID`) REFERENCES `companyprojectdetailcc` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorderdetail_SampleOrderDetailStatusID` FOREIGN KEY (`SampleOrderDetailStatusID`) REFERENCES `sampleorderdetailstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorderdetail_SampleOrderID` FOREIGN KEY (`SampleOrderID`) REFERENCES `sampleorder` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorderdetail_SatuanID` FOREIGN KEY (`SatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorderdetail_SuratJalanDetailID` FOREIGN KEY (`SuratJalanDetailID`) REFERENCES `suratjalandetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `sampleorderdetailassignment`
  ADD CONSTRAINT `sampleorderdetailassignment_SampleOrderDetailID` FOREIGN KEY (`SampleOrderDetailID`) REFERENCES `sampleorderdetail` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorderdetailassignment_SampleOrderDetailStatusID` FOREIGN KEY (`SampleOrderDetailStatusID`) REFERENCES `sampleorderdetailstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorderdetailassignment_SampleOrderID` FOREIGN KEY (`SampleOrderID`) REFERENCES `sampleorder` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `sampleorderdetailassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `sampleorderlink` ADD CONSTRAINT `sampleorderlink_SampleOrderID` FOREIGN KEY (`SampleOrderID`) REFERENCES `sampleorder` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `samplerequestimport`
  ADD CONSTRAINT `samplerequestimport_DeliveryID` FOREIGN KEY (`DeliveryID`) REFERENCES `delivery` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimport_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimport_ReferenceSRID` FOREIGN KEY (`ReferenceSRID`) REFERENCES `samplerequestimport` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimport_RequestFromID` FOREIGN KEY (`RequestFromID`) REFERENCES `samplerequestimportfrom` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimport_SampleRequestStatusID` FOREIGN KEY (`SampleRequestStatusID`) REFERENCES `samplerequeststatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimport_UrgencyID` FOREIGN KEY (`UrgencyID`) REFERENCES `urgency` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimport_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `samplerequestimportassignment`
  ADD CONSTRAINT `samplerequestimportassignment_SampleRequestImportID` FOREIGN KEY (`SampleRequestImportID`) REFERENCES `samplerequestimport` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportassignment_SampleRequestStatusID` FOREIGN KEY (`SampleRequestStatusID`) REFERENCES `samplerequeststatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `samplerequestimportdetail`
  ADD CONSTRAINT `samplerequestimportdetail_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportdetail_BaranglistID` FOREIGN KEY (`BaranglistID`) REFERENCES `baranglists` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportdetail_GoodReceiptDetailID` FOREIGN KEY (`GoodReceiptDetailID`) REFERENCES `samplerequestimportgoodsreceipt` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportdetail_ReqCompanyID` FOREIGN KEY (`ReqCompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportdetail_SampleRequestDetailStatusID` FOREIGN KEY (`SampleRequestDetailStatusID`) REFERENCES `samplerequeststatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportdetail_SampleRequestImportID` FOREIGN KEY (`SampleRequestImportID`) REFERENCES `samplerequestimport` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportdetail_SatuanID` FOREIGN KEY (`SatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `samplerequestimportdetailassignment`
  ADD CONSTRAINT `samplerequestimportdetailassignment_SampleRequestDetailID` FOREIGN KEY (`SampleRequestDetailID`) REFERENCES `samplerequestimportdetail` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportdetailassignment_SampleRequestDetailStatusID` FOREIGN KEY (`SampleRequestDetailStatusID`) REFERENCES `samplerequeststatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportdetailassignment_SampleRequestImportID` FOREIGN KEY (`SampleRequestImportID`) REFERENCES `samplerequestimport` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportdetailassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `samplerequestimportgoodsreceipt`
  ADD CONSTRAINT `samplerequestimportgoodsreceipt_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportgoodsreceipt_BarangListsID` FOREIGN KEY (`BarangListsID`) REFERENCES `baranglists` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportgoodsreceipt_SampleRequestImportDetailID` FOREIGN KEY (`SampleRequestImportDetailID`) REFERENCES `samplerequestimportdetail` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportgoodsreceipt_SampleRequestImportID` FOREIGN KEY (`SampleRequestImportID`) REFERENCES `samplerequestimport` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `samplerequestimportgoodsreceipt_SatuanID` FOREIGN KEY (`SatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `specialreference` ADD CONSTRAINT `specialreference_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `specialreferencehistory`
  ADD CONSTRAINT `specialreferencehistory_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `specialreferencehistory_SpecialReferenceID` FOREIGN KEY (`SpecialReferenceID`) REFERENCES `specialreference` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `specialreferencehistory_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `stockopname`
  ADD CONSTRAINT `stockopname_PackagingID` FOREIGN KEY (`PackagingID`) REFERENCES `packing` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopname_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `stockopname_principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopname_ProductID` FOREIGN KEY (`ProductID`) REFERENCES `stockopname_product` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopname_StockOpnameBy` FOREIGN KEY (`StockOpnameBy`) REFERENCES `stockopnameby` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopname_UOMID` FOREIGN KEY (`UOMID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopname_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopname_WarehouseID` FOREIGN KEY (`WarehouseID`) REFERENCES `warehouse` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `stockopname_product`
  ADD CONSTRAINT `stockopname_product_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `stockopname_principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopname_product_UOMID` FOREIGN KEY (`UOMID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `stockopnamehistory`
  ADD CONSTRAINT `stockopnamehistory_PackagingID` FOREIGN KEY (`PackagingID`) REFERENCES `packing` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopnamehistory_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `stockopname_principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopnamehistory_ProductID` FOREIGN KEY (`ProductID`) REFERENCES `stockopname_product` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopnamehistory_StockOpnameBy` FOREIGN KEY (`StockOpnameBy`) REFERENCES `stockopnameby` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopnamehistory_StockOpnameID` FOREIGN KEY (`StockOpnameID`) REFERENCES `stockopname` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopnamehistory_StockOpnameStatusID` FOREIGN KEY (`StockOpnameStatusID`) REFERENCES `stockopnamestatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopnamehistory_UOMID` FOREIGN KEY (`UOMID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopnamehistory_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `stockopnamehistory_WarehouseID` FOREIGN KEY (`WarehouseID`) REFERENCES `warehouse` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `successstory`
  ADD CONSTRAINT `successstory_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `successstory_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `successstory_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `successstory_GroupDivisionID` FOREIGN KEY (`GroupDivisionID`) REFERENCES `groupdivision` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `successstory_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `successstory_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `successstory_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `successstoryassignment`
  ADD CONSTRAINT `successstoryassignment_SuccessStoryID` FOREIGN KEY (`SuccessStoryID`) REFERENCES `successstory` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `successstoryassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `suratjalan`
  ADD CONSTRAINT `suratjalan_CompanyCPID` FOREIGN KEY (`CompanyCPID`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `suratjalan_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `suratjalan_DeliveryID` FOREIGN KEY (`DeliveryID`) REFERENCES `delivery` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `suratjalan_LocationID` FOREIGN KEY (`LocationID`) REFERENCES `location` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `suratjalan_SampleOrderID` FOREIGN KEY (`SampleOrderID`) REFERENCES `sampleorder` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `suratjalan_UserIDCreatorSJ` FOREIGN KEY (`UserIDCreatorSJ`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `suratjalan_UserIDsales` FOREIGN KEY (`UserIDsales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `suratjalandetails`
  ADD CONSTRAINT `suratjalandetails_ApplicationID` FOREIGN KEY (`ApplicationID`) REFERENCES `application` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `suratjalandetails_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `suratjalandetails_BarangListID` FOREIGN KEY (`BarangListID`) REFERENCES `baranglists` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `suratjalandetails_SampleOrderID` FOREIGN KEY (`SampleOrderID`) REFERENCES `sampleorder` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `suratjalandetails_SatuanID` FOREIGN KEY (`SatuanID`) REFERENCES `satuan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `suratjalandetails_SuratJalanID` FOREIGN KEY (`SuratJalanID`) REFERENCES `suratjalan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `userbusinesstravelbranch`
  ADD CONSTRAINT `userbusinesstravelbranch_BranchID` FOREIGN KEY (`BranchID`) REFERENCES `branch` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `userbusinesstravelbranch_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `userdetails`
  ADD CONSTRAINT `userdetails_BranchID` FOREIGN KEY (`BranchID`) REFERENCES `branch` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `userdetails_DepartmentID` FOREIGN KEY (`DepartmentID`) REFERENCES `department` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `userdetails_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `userdivision`
  ADD CONSTRAINT `userdivision_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `userdivision_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `usereducation`
  ADD CONSTRAINT `usereducation_EducationID` FOREIGN KEY (`EducationID`) REFERENCES `education` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `usereducation_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `userjob` ADD CONSTRAINT `userjob_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `userlabgroupdivision`
  ADD CONSTRAINT `userlabgroupdivision_GroupDivisionID` FOREIGN KEY (`GroupDivisionID`) REFERENCES `groupdivision` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `userlabgroupdivision_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `userprincipal`
  ADD CONSTRAINT `userprincipal_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `userprincipal_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `users`
  ADD CONSTRAINT `users_BranchID` FOREIGN KEY (`BranchID`) REFERENCES `branch` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `users_DepartmentID` FOREIGN KEY (`DepartmentID`) REFERENCES `department` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `users_HeadID` FOREIGN KEY (`HeadID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `users_MaritalStatusID` FOREIGN KEY (`MaritalStatusID`) REFERENCES `maritalstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `users_RoleID` FOREIGN KEY (`RoleID`) REFERENCES `role` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `usersperiode` ADD CONSTRAINT `usersperiode_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `userwarehouse`
  ADD CONSTRAINT `userwarehouse_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `userwarehouse_WarehouseID` FOREIGN KEY (`WarehouseID`) REFERENCES `warehouse` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `vehicle`
  ADD CONSTRAINT `vehicle_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicle_UserIDOwner` FOREIGN KEY (`UserIDOwner`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicle_VehicleBrandID` FOREIGN KEY (`VehicleBrandID`) REFERENCES `vehiclebrand` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicle_VehicleBrandTypeID` FOREIGN KEY (`VehicleBrandTypeID`) REFERENCES `vehiclebrandtype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicle_VehicleColorID` FOREIGN KEY (`VehicleColorID`) REFERENCES `vehiclecolor` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicle_VehicleFuelTypeID` FOREIGN KEY (`VehicleFuelTypeID`) REFERENCES `vehiclefueltype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicle_VehicleTypeID` FOREIGN KEY (`VehicleTypeID`) REFERENCES `vehicletype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `vehicleassignment`
  ADD CONSTRAINT `vehicleassignment_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_UserIDOwnerAfter` FOREIGN KEY (`UserIDOwnerAfter`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_UserIDOwnerBefore` FOREIGN KEY (`UserIDOwnerBefore`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_VehicleBrandIDAfter` FOREIGN KEY (`VehicleBrandIDAfter`) REFERENCES `vehiclebrand` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_VehicleBrandIDBefore` FOREIGN KEY (`VehicleBrandIDBefore`) REFERENCES `vehiclebrand` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_VehicleBrandTypeIDAfter` FOREIGN KEY (`VehicleBrandTypeIDAfter`) REFERENCES `vehiclebrandtype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_VehicleBrandTypeIDBefore` FOREIGN KEY (`VehicleBrandTypeIDBefore`) REFERENCES `vehiclebrandtype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_VehicleColorIDAfter` FOREIGN KEY (`VehicleColorIDAfter`) REFERENCES `vehiclecolor` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_VehicleColroIDBefore` FOREIGN KEY (`VehicleColorIDBefore`) REFERENCES `vehiclecolor` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_VehicleFuelTypeIDAfter` FOREIGN KEY (`VehicleFuelTypeIDAfter`) REFERENCES `vehiclefueltype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_VehicleFuelTypeIDBefore` FOREIGN KEY (`VehicleFuelTypeIDBefore`) REFERENCES `vehiclefueltype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_VehicleID` FOREIGN KEY (`VehicleID`) REFERENCES `vehicle` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_VehicleStatusID` FOREIGN KEY (`VehicleStatusID`) REFERENCES `vehiclestatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_VehicleTypeIDAfter` FOREIGN KEY (`VehicleTypeIDAfter`) REFERENCES `vehicletype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleassignment_VehicleTypeIDBefore` FOREIGN KEY (`VehicleTypeIDBefore`) REFERENCES `vehicletype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `vehiclebrandtype` ADD CONSTRAINT `vehiclebrandtype_VehicleBrandID` FOREIGN KEY (`VehicleBrandID`) REFERENCES `vehiclebrand` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `vehicleservicerequest`
  ADD CONSTRAINT `vehicleservicerequest_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleservicerequest_UserIDOwner` FOREIGN KEY (`UserIDOwner`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleservicerequest_VehicleID` FOREIGN KEY (`VehicleID`) REFERENCES `vehicle` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleservicerequest_VehicleServiceRequestStatusID` FOREIGN KEY (`VehicleServiceRequestStatusID`) REFERENCES `vehicleservicerequeststatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `vehicleservicerequestassignment`
  ADD CONSTRAINT `vehicleservicerequestassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleservicerequestassignment_VehicleServiceRequestID` FOREIGN KEY (`VehicleServiceRequestID`) REFERENCES `vehicleservicerequest` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleservicerequestassignment_VehicleServiceRequestStatusID` FOREIGN KEY (`VehicleServiceRequestStatusID`) REFERENCES `vehicleservicerequeststatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `vehicleservicerequestdetails`
  ADD CONSTRAINT `vehicleservicerequestdetails_VehicleServiceRequestDetailStatus` FOREIGN KEY (`VehicleServiceRequestDetailStatus`) REFERENCES `vehicleservicerequeststatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleservicerequestdetails_VehicleServiceRequestID` FOREIGN KEY (`VehicleServiceRequestID`) REFERENCES `vehicleservicerequest` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleservicerequestdetails_VehicleServiceTypeID` FOREIGN KEY (`VehicleServiceTypeID`) REFERENCES `vehicleservicetype` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `vehicleservicerequestdetailsassigntment`
  ADD CONSTRAINT `vehicleservicerequestdetailsassigntment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleservicerequestdetailsassigntment_VehSerReqDetailID` FOREIGN KEY (`VehicleServiceRequestDetailID`) REFERENCES `vehicleservicerequestdetails` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleservicerequestdetailsassigntment_VehSerReqStatusID` FOREIGN KEY (`VehicleServiceRequestStatusID`) REFERENCES `vehicleservicerequeststatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `vehicleservicerequestdetailsassigntment_VehicleServiceRequestID` FOREIGN KEY (`VehicleServiceRequestID`) REFERENCES `vehicleservicerequest` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `visitplan`
  ADD CONSTRAINT `visitplan_CompanyCPID` FOREIGN KEY (`CompanyCPID`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplan_CompanyID` FOREIGN KEY (`CompanyID`) REFERENCES `company` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplan_DivisionID` FOREIGN KEY (`DivisionID`) REFERENCES `division` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplan_ProjectID` FOREIGN KEY (`ProjectID`) REFERENCES `companyproject` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplan_UserIDInput` FOREIGN KEY (`UserIDInput`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplan_UserIDSales` FOREIGN KEY (`UserIDSales`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplan_UserIDVisitWith` FOREIGN KEY (`UserIDVisitWith`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplan_VisitPlanStatusID` FOREIGN KEY (`VisitPlanStatusID`) REFERENCES `visitplanstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplan_VisitPrincipalCPID` FOREIGN KEY (`VisitPrincipalCPID`) REFERENCES `principalcp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplan_VisitingPrincipalID` FOREIGN KEY (`VisitingPrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `visitplanassignment`
  ADD CONSTRAINT `visitplanassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplanassignment_VisitPlanID` FOREIGN KEY (`VisitPlanID`) REFERENCES `visitplan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplanassignment_VisitPlanStatusID` FOREIGN KEY (`VisitPlanStatusID`) REFERENCES `visitplanstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `visitplancompanycpdetail`
  ADD CONSTRAINT `visitplancompanycpdetail_CompanyCPID` FOREIGN KEY (`CompanyCPID`) REFERENCES `companycp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplancompanycpdetail_VisitPlanID` FOREIGN KEY (`VisitPlanID`) REFERENCES `visitplan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `visitplandetail`
  ADD CONSTRAINT `visitplandetail_ActionID` FOREIGN KEY (`ActionID`) REFERENCES `action` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplandetail_BarangID` FOREIGN KEY (`BarangID`) REFERENCES `barang` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplandetail_PrincipalID` FOREIGN KEY (`PrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplandetail_ProjectID` FOREIGN KEY (`ProjectID`) REFERENCES `companyprojectdetailcc` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplandetail_VisitActionStatusID` FOREIGN KEY (`VisitActionStatusID`) REFERENCES `visitplanstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplandetail_VisitPlanID` FOREIGN KEY (`VisitPlanID`) REFERENCES `visitplan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `visitplandetailassignment`
  ADD CONSTRAINT `visitplandetailassignment_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplandetailassignment_VisitActionStatusID` FOREIGN KEY (`VisitActionStatusID`) REFERENCES `visitplanstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplandetailassignment_VisitPlanDetailID` FOREIGN KEY (`VisitPlanDetailID`) REFERENCES `visitplandetail` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplandetailassignment_VisitPlanID` FOREIGN KEY (`VisitPlanID`) REFERENCES `visitplan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplandetailassignment_VisitPlanStatusID` FOREIGN KEY (`VisitPlanStatusID`) REFERENCES `visitplanstatus` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `visitplanfrienddetail`
  ADD CONSTRAINT `visitplanfrienddetail_UserIDVisitWith` FOREIGN KEY (`UserIDVisitWith`) REFERENCES `users` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplanfrienddetail_VisitPlanID` FOREIGN KEY (`VisitPlanID`) REFERENCES `visitplan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `visitplanlink` ADD CONSTRAINT `visitplanlink_VisitPlanID` FOREIGN KEY (`VisitPlanID`) REFERENCES `visitplan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `visitplanprincipalvisitdetail`
  ADD CONSTRAINT `visitplanprincipalvisitdetail_VisitPlanID` FOREIGN KEY (`VisitPlanID`) REFERENCES `visitplan` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplanprincipalvisitdetail_VisitingPrincipalCPID` FOREIGN KEY (`VisitingPrincipalCPID`) REFERENCES `principalcp` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  ADD CONSTRAINT `visitplanprincipalvisitdetail_VisitingPrincipalID` FOREIGN KEY (`VisitingPrincipalID`) REFERENCES `principal` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `warehouse` ADD CONSTRAINT `warehouse_ParentID` FOREIGN KEY (`ParentID`) REFERENCES `warehouse` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;


-- ---------------------------------------------------------------------
-- SECTION 9 - Seed `migrations`   (NEW 2026-08-14)
--
-- THIS IS THE LAST THING THE SCRIPT DOES, ON PURPOSE. It is the only INSERT in the file, and it
-- is the script's own record that it finished. If the run dies anywhere above this point,
-- `migrations` stays empty and `php artisan migrate` will not be fooled into thinking the
-- schema work was done.
--
-- WHY SEED AT ALL. Production has never run a migration, so without this `php artisan migrate`
-- would replay all 31 from scratch against a database this script has already converged --
-- re-renaming `users.username` (a no-op that hides the problem), re-creating `sessions` (error
-- 42S01), re-adding `menu`.`Icon` (error 1060), and re-validating foreign keys for nothing.
--
-- 28 rows, all at batch 1. Batch 1 is the truthful record: production receives all of this in
-- ONE operation. Dev's 22 batches describe dev's history, not production's. `id` is
-- AUTO_INCREMENT and is deliberately not supplied. The string Laravel stores is the migration
-- FILENAME WITHOUT `.php` -- confirmed by set-comparing all 31 filenames against dev's
-- `migrations` rows: the only difference is the single pending migration, and no row lacks a
-- matching file.
--
-- ⚠⚠ FOUR MIGRATIONS ARE DELIBERATELY WITHHELD FROM THIS LIST. Each does real work that this
-- script cannot do, so marking it "already run" would silently lose that work. After this
-- script, `php artisan migrate` is therefore NOT a no-op -- it is a short, guarded pass that
-- does exactly these four things. Run it. Check with `php artisan migrate --pretend` first.
--
--   2026_06_29_130000_add_is_stock_returnable_to_sampleorderdetail
--       Section 3b adds `sampleorderdetail`.`IsStockReturnable` with DEFAULT '0' and NEVER
--       BACKFILLS IT -- the whole script contains no INSERT and no UPDATE touching that column.
--       The migration backfills `= 1` where BarangListID > 0 AND SampleOrderDetailStatusID IN
--       (3,4). On 63 that is 448 of 2,333 rows. Seeded, production's column stays all-zero and
--       Change-Status backward stock compensation under-credits every packed / in-transit line.
--
--   2026_07_02_134940_seed_visitplanstatus_lookup
--       Inserts 11 lookup rows. This script seeds nothing, and section 8 hangs FIVE RESTRICT
--       foreign keys off `visitplanstatus`. The migration self-guards (returns early if the
--       table has rows), so letting it run costs nothing and skipping it can kill the module.
--       🔥 SEE THE WARNING IN THE AUDIT, PART 0b, CHECK 7. Section 6 of THIS script NULLs every
--       visit-plan status that does not resolve against `visitplanstatus`, and it runs long
--       before artisan does. If production's lookup is empty when you run this script, the
--       script itself wipes the statuses. Seeding the lookup afterwards cannot bring them back.
--
--   2026_08_01_100000_add_quotation_list_indexes
--       Creates the two Quotation-list pagination indexes this script deliberately omits.
--       Idempotent, MariaDB-aware, and it sets its own lock_wait_timeout. See DELIBERATE
--       EXCLUSIONS at the top of this file.
--
--   2026_08_09_100000_create_notification_table
--       Section 2b already creates `notification` with byte-identical DDL, but the migration
--       holds the authoritative definition and guards itself with tableExists(). Leaving it
--       unseeded makes the artisan pass a verified no-op instead of an assumed one -- belt and
--       braces at zero cost.
--
-- ⚠ NEVER RUN `php artisan migrate:rollback` ON PRODUCTION. With everything at batch 1, one
--   stray rollback attempts 27 `down()` methods, several of which drop constraints or columns.
--   Consider revoking ALTER and DROP from the application's runtime database user after cutover.
-- ---------------------------------------------------------------------
INSERT INTO `migrations` (`migration`, `batch`) VALUES
  ('0001_01_01_000000_create_users_table', 1),
  ('0001_01_01_000001_create_cache_table', 1),
  ('0001_01_01_000002_create_jobs_table', 1),
  ('2026_05_19_100000_add_password_reset_columns_to_users_table', 1),
  ('2026_05_28_074227_add_icon_to_menu_table', 1),
  ('2026_05_29_025236_rename_users_columns_to_pascalcase_and_widen_password', 1),
  ('2026_06_29_120000_drop_mismatched_company_product_pivot_fks', 1),
  ('2026_07_02_134941_add_auto_increment_to_visitplan_ids', 1),
  ('2026_07_09_120000_fix_companyprojectdetailcomp_productidcomp_fk_to_barang', 1),
  ('2026_07_22_120000_drop_lying_complain_department_fks', 1),
  ('2026_07_22_130000_drop_department_fks_on_complainitem_tables', 1),
  ('2026_07_23_120000_add_auto_increment_to_vehicleservicerequest_ids', 1),
  ('2026_07_24_090000_add_auto_increment_to_vehicletype_id', 1),
  ('2026_07_24_090100_add_auto_increment_to_vehiclebrand_id', 1),
  ('2026_07_24_090200_add_auto_increment_to_vehiclecolor_id', 1),
  ('2026_07_24_090300_add_auto_increment_to_vehiclefueltype_id', 1),
  ('2026_07_24_090400_add_auto_increment_to_vehiclebrandtype_id', 1),
  ('2026_07_24_090500_add_auto_increment_to_vehicleassignment_id', 1),
  ('2026_07_24_120000_repoint_company_product_pivot_fks_to_master_tables', 1),
  ('2026_08_06_120000_repoint_project_detail_fks_to_companyprojectdetailcc', 1),
  ('2026_08_13_100000_widen_remark_columns_to_text', 1),
  ('2026_08_13_100100_restructure_country_to_int_pk_with_code', 1),
  ('2026_08_13_100200_repoint_salesrebateinvoice_status_fks_to_detailstatus', 1),
  ('2026_08_13_100300_add_legacy_only_columns_to_match_production', 1),
  ('2026_08_13_100400_widen_decimals_to_match_legacy_precision', 1),
  ('2026_08_13_100500_relax_depname_to_match_legacy', 1),
  ('2026_08_14_100000_drop_wrong_paymentterm_fks', 1),
  ('2026_08_14_100100_narrow_quotation_decimals_to_match_legacy', 1);

-- IFNULL on both: running the file in pieces (which "not resumable" practically invites) leaves
-- these user variables NULL, and `SET SESSION x = NULL` is ERROR 1232, not a no-op. The fallback
-- values are MariaDB 10.4's own defaults.
--
-- ⚠ THE `CAST(... AS UNSIGNED)` IS LOAD-BEARING. Without it this is ERROR 1232 EVERY TIME, not
--   only when the variable is NULL: a bare user variable assigns fine, but wrapping it in
--   IFNULL() changes the result's type to one the server refuses for an integer system variable.
--   Found by running the file, not by reading it -- the first version of this fix failed on the
--   very last line of an otherwise perfect 103-second run, turning rc=0 into rc=1 after all the
--   work had already succeeded. Verified all four ways: bare IFNULL errors; with the CAST it
--   restores 31536000 when the variable is set and falls back to 86400 / 50 when it is NULL.
SET SESSION lock_wait_timeout = CAST(IFNULL(@OLD_LOCK_WAIT, 86400) AS UNSIGNED);
SET SESSION innodb_lock_wait_timeout = CAST(IFNULL(@OLD_INNODB_LOCK_WAIT, 50) AS UNSIGNED);
