SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `samplerequestimportdetailassignment` c
  LEFT JOIN `samplerequestimportdetail` p0 ON c.`SampleRequestDetailID` = p0.`ID`
  LEFT JOIN `samplerequeststatus` p1 ON c.`SampleRequestDetailStatusID` = p1.`ID`
  LEFT JOIN `samplerequestimport` p2 ON c.`SampleRequestImportID` = p2.`ID`
  LEFT JOIN `users` p3 ON c.`UserID` = p3.`ID`
 WHERE  (c.`SampleRequestDetailID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`SampleRequestDetailStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`SampleRequestImportID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `samplerequestimportgoodsreceipt` c
  LEFT JOIN `barang` p0 ON c.`BarangID` = p0.`ID`
  LEFT JOIN `baranglists` p1 ON c.`BarangListsID` = p1.`ID`
  LEFT JOIN `samplerequestimportdetail` p2 ON c.`SampleRequestImportDetailID` = p2.`ID`
  LEFT JOIN `samplerequestimport` p3 ON c.`SampleRequestImportID` = p3.`ID`
  LEFT JOIN `satuan` p4 ON c.`SatuanID` = p4.`ID`
 WHERE  (c.`BarangID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BarangListsID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`SampleRequestImportDetailID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`SampleRequestImportID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`SatuanID` IS NOT NULL AND p4.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `specialreference` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
 WHERE  (c.`CompanyID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `specialreferencehistory` c
  LEFT JOIN `company` p0 ON c.`CompanyID` = p0.`ID`
  LEFT JOIN `specialreference` p1 ON c.`SpecialReferenceID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserID` = p2.`ID`
 WHERE  (c.`CompanyID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`SpecialReferenceID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `stockopname` c
  LEFT JOIN `packing` p0 ON c.`PackagingID` = p0.`ID`
  LEFT JOIN `stockopname_principal` p1 ON c.`PrincipalID` = p1.`ID`
  LEFT JOIN `stockopname_product` p2 ON c.`ProductID` = p2.`ID`
  LEFT JOIN `stockopnameby` p3 ON c.`StockOpnameBy` = p3.`ID`
  LEFT JOIN `satuan` p4 ON c.`UOMID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDInput` = p5.`ID`
  LEFT JOIN `warehouse` p6 ON c.`WarehouseID` = p6.`ID`
 WHERE  (c.`PackagingID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`ProductID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`StockOpnameBy` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`UOMID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`WarehouseID` IS NOT NULL AND p6.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `stockopname_product` c
  LEFT JOIN `stockopname_principal` p0 ON c.`PrincipalID` = p0.`ID`
  LEFT JOIN `satuan` p1 ON c.`UOMID` = p1.`ID`
 WHERE  (c.`PrincipalID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UOMID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `stockopnamehistory` c
  LEFT JOIN `packing` p0 ON c.`PackagingID` = p0.`ID`
  LEFT JOIN `stockopname_principal` p1 ON c.`PrincipalID` = p1.`ID`
  LEFT JOIN `stockopname_product` p2 ON c.`ProductID` = p2.`ID`
  LEFT JOIN `stockopnameby` p3 ON c.`StockOpnameBy` = p3.`ID`
  LEFT JOIN `stockopname` p4 ON c.`StockOpnameID` = p4.`ID`
  LEFT JOIN `stockopnamestatus` p5 ON c.`StockOpnameStatusID` = p5.`ID`
  LEFT JOIN `satuan` p6 ON c.`UOMID` = p6.`ID`
  LEFT JOIN `users` p7 ON c.`UserIDInput` = p7.`ID`
  LEFT JOIN `warehouse` p8 ON c.`WarehouseID` = p8.`ID`
 WHERE  (c.`PackagingID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`ProductID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`StockOpnameBy` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`StockOpnameID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`StockOpnameStatusID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`UOMID` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`WarehouseID` IS NOT NULL AND p8.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `successstory` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `groupdivision` p3 ON c.`GroupDivisionID` = p3.`ID`
  LEFT JOIN `principal` p4 ON c.`PrincipalID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDInput` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDSales` = p6.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BarangID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`GroupDivisionID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p6.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `successstoryassignment` c
  LEFT JOIN `successstory` p0 ON c.`SuccessStoryID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
 WHERE  (c.`SuccessStoryID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `suratjalan` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `delivery` p2 ON c.`DeliveryID` = p2.`ID`
  LEFT JOIN `location` p3 ON c.`LocationID` = p3.`ID`
  LEFT JOIN `sampleorder` p4 ON c.`SampleOrderID` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDCreatorSJ` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDsales` = p6.`ID`
 WHERE  (c.`CompanyCPID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DeliveryID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`LocationID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`SampleOrderID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`UserIDCreatorSJ` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`UserIDsales` IS NOT NULL AND p6.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `suratjalandetails` c
  LEFT JOIN `application` p0 ON c.`ApplicationID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `baranglists` p2 ON c.`BarangListID` = p2.`ID`
  LEFT JOIN `sampleorder` p3 ON c.`SampleOrderID` = p3.`ID`
  LEFT JOIN `satuan` p4 ON c.`SatuanID` = p4.`ID`
  LEFT JOIN `suratjalan` p5 ON c.`SuratJalanID` = p5.`ID`
 WHERE  (c.`ApplicationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BarangID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`BarangListID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`SampleOrderID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`SatuanID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`SuratJalanID` IS NOT NULL AND p5.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `userbusinesstravelbranch` c
  LEFT JOIN `branch` p0 ON c.`BranchID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
 WHERE  (c.`BranchID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `userdetails` c
  LEFT JOIN `branch` p0 ON c.`BranchID` = p0.`ID`
  LEFT JOIN `department` p1 ON c.`DepartmentID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
 WHERE  (c.`BranchID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`DepartmentID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `userdivision` c
  LEFT JOIN `division` p0 ON c.`DivisionID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
 WHERE  (c.`DivisionID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `usereducation` c
  LEFT JOIN `education` p0 ON c.`EducationID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
 WHERE  (c.`EducationID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `userjob` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
 WHERE  (c.`UserID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `userlabgroupdivision` c
  LEFT JOIN `groupdivision` p0 ON c.`GroupDivisionID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
 WHERE  (c.`GroupDivisionID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `userprincipal` c
  LEFT JOIN `principal` p0 ON c.`PrincipalID` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserID` = p1.`ID`
 WHERE  (c.`PrincipalID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `users` c
  LEFT JOIN `branch` p0 ON c.`BranchID` = p0.`ID`
  LEFT JOIN `department` p1 ON c.`DepartmentID` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`HeadID` = p2.`ID`
  LEFT JOIN `maritalstatus` p3 ON c.`MaritalStatusID` = p3.`ID`
  LEFT JOIN `role` p4 ON c.`RoleID` = p4.`ID`
 WHERE  (c.`BranchID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`DepartmentID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`HeadID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`MaritalStatusID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`RoleID` IS NOT NULL AND p4.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `usersperiode` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
 WHERE  (c.`UserID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `userwarehouse` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
  LEFT JOIN `warehouse` p1 ON c.`WarehouseID` = p1.`ID`
 WHERE  (c.`UserID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`WarehouseID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `vehicle` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserIDOwner` = p1.`ID`
  LEFT JOIN `vehiclebrand` p2 ON c.`VehicleBrandID` = p2.`ID`
  LEFT JOIN `vehiclebrandtype` p3 ON c.`VehicleBrandTypeID` = p3.`ID`
  LEFT JOIN `vehiclecolor` p4 ON c.`VehicleColorID` = p4.`ID`
  LEFT JOIN `vehiclefueltype` p5 ON c.`VehicleFuelTypeID` = p5.`ID`
  LEFT JOIN `vehicletype` p6 ON c.`VehicleTypeID` = p6.`ID`
 WHERE  (c.`UserIDInput` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserIDOwner` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`VehicleBrandID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`VehicleBrandTypeID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`VehicleColorID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`VehicleFuelTypeID` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`VehicleTypeID` IS NOT NULL AND p6.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `vehicleassignment` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserIDOwnerAfter` = p1.`ID`
  LEFT JOIN `users` p2 ON c.`UserIDOwnerBefore` = p2.`ID`
  LEFT JOIN `vehiclebrand` p3 ON c.`VehicleBrandIDAfter` = p3.`ID`
  LEFT JOIN `vehiclebrand` p4 ON c.`VehicleBrandIDBefore` = p4.`ID`
  LEFT JOIN `vehiclebrandtype` p5 ON c.`VehicleBrandTypeIDAfter` = p5.`ID`
  LEFT JOIN `vehiclebrandtype` p6 ON c.`VehicleBrandTypeIDBefore` = p6.`ID`
  LEFT JOIN `vehiclecolor` p7 ON c.`VehicleColorIDAfter` = p7.`ID`
  LEFT JOIN `vehiclecolor` p8 ON c.`VehicleColorIDBefore` = p8.`ID`
  LEFT JOIN `vehiclefueltype` p9 ON c.`VehicleFuelTypeIDAfter` = p9.`ID`
  LEFT JOIN `vehiclefueltype` p10 ON c.`VehicleFuelTypeIDBefore` = p10.`ID`
  LEFT JOIN `vehicle` p11 ON c.`VehicleID` = p11.`ID`
 WHERE  (c.`UserIDInput` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserIDOwnerAfter` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`UserIDOwnerBefore` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`VehicleBrandIDAfter` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`VehicleBrandIDBefore` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`VehicleBrandTypeIDAfter` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`VehicleBrandTypeIDBefore` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`VehicleColorIDAfter` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`VehicleColorIDBefore` IS NOT NULL AND p8.`ID` IS NULL)
    OR (c.`VehicleFuelTypeIDAfter` IS NOT NULL AND p9.`ID` IS NULL)
    OR (c.`VehicleFuelTypeIDBefore` IS NOT NULL AND p10.`ID` IS NULL)
    OR (c.`VehicleID` IS NOT NULL AND p11.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `vehicleassignment` c
  LEFT JOIN `vehiclestatus` p0 ON c.`VehicleStatusID` = p0.`ID`
  LEFT JOIN `vehicletype` p1 ON c.`VehicleTypeIDAfter` = p1.`ID`
  LEFT JOIN `vehicletype` p2 ON c.`VehicleTypeIDBefore` = p2.`ID`
 WHERE  (c.`VehicleStatusID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`VehicleTypeIDAfter` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`VehicleTypeIDBefore` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `vehiclebrandtype` c
  LEFT JOIN `vehiclebrand` p0 ON c.`VehicleBrandID` = p0.`ID`
 WHERE  (c.`VehicleBrandID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `vehicleservicerequest` c
  LEFT JOIN `users` p0 ON c.`UserIDInput` = p0.`ID`
  LEFT JOIN `users` p1 ON c.`UserIDOwner` = p1.`ID`
  LEFT JOIN `vehicle` p2 ON c.`VehicleID` = p2.`ID`
  LEFT JOIN `vehicleservicerequeststatus` p3 ON c.`VehicleServiceRequestStatusID` = p3.`ID`
 WHERE  (c.`UserIDInput` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`UserIDOwner` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`VehicleID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`VehicleServiceRequestStatusID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `vehicleservicerequestassignment` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
  LEFT JOIN `vehicleservicerequest` p1 ON c.`VehicleServiceRequestID` = p1.`ID`
  LEFT JOIN `vehicleservicerequeststatus` p2 ON c.`VehicleServiceRequestStatusID` = p2.`ID`
 WHERE  (c.`UserID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`VehicleServiceRequestID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`VehicleServiceRequestStatusID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `vehicleservicerequestdetails` c
  LEFT JOIN `vehicleservicerequeststatus` p0 ON c.`VehicleServiceRequestDetailStatus` = p0.`ID`
  LEFT JOIN `vehicleservicerequest` p1 ON c.`VehicleServiceRequestID` = p1.`ID`
  LEFT JOIN `vehicleservicetype` p2 ON c.`VehicleServiceTypeID` = p2.`ID`
 WHERE  (c.`VehicleServiceRequestDetailStatus` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`VehicleServiceRequestID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`VehicleServiceTypeID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `vehicleservicerequestdetailsassigntment` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
  LEFT JOIN `vehicleservicerequestdetails` p1 ON c.`VehicleServiceRequestDetailID` = p1.`ID`
  LEFT JOIN `vehicleservicerequeststatus` p2 ON c.`VehicleServiceRequestStatusID` = p2.`ID`
  LEFT JOIN `vehicleservicerequest` p3 ON c.`VehicleServiceRequestID` = p3.`ID`
 WHERE  (c.`UserID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`VehicleServiceRequestDetailID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`VehicleServiceRequestStatusID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`VehicleServiceRequestID` IS NOT NULL AND p3.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `visitplan` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `company` p1 ON c.`CompanyID` = p1.`ID`
  LEFT JOIN `division` p2 ON c.`DivisionID` = p2.`ID`
  LEFT JOIN `companyproject` p3 ON c.`ProjectID` = p3.`ID`
  LEFT JOIN `users` p4 ON c.`UserIDInput` = p4.`ID`
  LEFT JOIN `users` p5 ON c.`UserIDSales` = p5.`ID`
  LEFT JOIN `users` p6 ON c.`UserIDVisitWith` = p6.`ID`
  LEFT JOIN `visitplanstatus` p7 ON c.`VisitPlanStatusID` = p7.`ID`
  LEFT JOIN `principalcp` p8 ON c.`VisitPrincipalCPID` = p8.`ID`
  LEFT JOIN `principal` p9 ON c.`VisitingPrincipalID` = p9.`ID`
 WHERE  (c.`CompanyCPID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`CompanyID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`DivisionID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`ProjectID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`UserIDInput` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`UserIDSales` IS NOT NULL AND p5.`ID` IS NULL)
    OR (c.`UserIDVisitWith` IS NOT NULL AND p6.`ID` IS NULL)
    OR (c.`VisitPlanStatusID` IS NOT NULL AND p7.`ID` IS NULL)
    OR (c.`VisitPrincipalCPID` IS NOT NULL AND p8.`ID` IS NULL)
    OR (c.`VisitingPrincipalID` IS NOT NULL AND p9.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `visitplanassignment` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
  LEFT JOIN `visitplan` p1 ON c.`VisitPlanID` = p1.`ID`
  LEFT JOIN `visitplanstatus` p2 ON c.`VisitPlanStatusID` = p2.`ID`
 WHERE  (c.`UserID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`VisitPlanID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`VisitPlanStatusID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `visitplancompanycpdetail` c
  LEFT JOIN `companycp` p0 ON c.`CompanyCPID` = p0.`ID`
  LEFT JOIN `visitplan` p1 ON c.`VisitPlanID` = p1.`ID`
 WHERE  (c.`CompanyCPID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`VisitPlanID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `visitplandetail` c
  LEFT JOIN `action` p0 ON c.`ActionID` = p0.`ID`
  LEFT JOIN `barang` p1 ON c.`BarangID` = p1.`ID`
  LEFT JOIN `principal` p2 ON c.`PrincipalID` = p2.`ID`
  LEFT JOIN `companyprojectdetailcc` p3 ON c.`ProjectID` = p3.`ID`
  LEFT JOIN `visitplanstatus` p4 ON c.`VisitActionStatusID` = p4.`ID`
  LEFT JOIN `visitplan` p5 ON c.`VisitPlanID` = p5.`ID`
 WHERE  (c.`ActionID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`BarangID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`PrincipalID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`ProjectID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`VisitActionStatusID` IS NOT NULL AND p4.`ID` IS NULL)
    OR (c.`VisitPlanID` IS NOT NULL AND p5.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `visitplandetailassignment` c
  LEFT JOIN `users` p0 ON c.`UserID` = p0.`ID`
  LEFT JOIN `visitplanstatus` p1 ON c.`VisitActionStatusID` = p1.`ID`
  LEFT JOIN `visitplandetail` p2 ON c.`VisitPlanDetailID` = p2.`ID`
  LEFT JOIN `visitplan` p3 ON c.`VisitPlanID` = p3.`ID`
  LEFT JOIN `visitplanstatus` p4 ON c.`VisitPlanStatusID` = p4.`ID`
 WHERE  (c.`UserID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`VisitActionStatusID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`VisitPlanDetailID` IS NOT NULL AND p2.`ID` IS NULL)
    OR (c.`VisitPlanID` IS NOT NULL AND p3.`ID` IS NULL)
    OR (c.`VisitPlanStatusID` IS NOT NULL AND p4.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `visitplanfrienddetail` c
  LEFT JOIN `users` p0 ON c.`UserIDVisitWith` = p0.`ID`
  LEFT JOIN `visitplan` p1 ON c.`VisitPlanID` = p1.`ID`
 WHERE  (c.`UserIDVisitWith` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`VisitPlanID` IS NOT NULL AND p1.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `visitplanlink` c
  LEFT JOIN `visitplan` p0 ON c.`VisitPlanID` = p0.`ID`
 WHERE  (c.`VisitPlanID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `visitplanprincipalvisitdetail` c
  LEFT JOIN `visitplan` p0 ON c.`VisitPlanID` = p0.`ID`
  LEFT JOIN `principalcp` p1 ON c.`VisitingPrincipalCPID` = p1.`ID`
  LEFT JOIN `principal` p2 ON c.`VisitingPrincipalID` = p2.`ID`
 WHERE  (c.`VisitPlanID` IS NOT NULL AND p0.`ID` IS NULL)
    OR (c.`VisitingPrincipalCPID` IS NOT NULL AND p1.`ID` IS NULL)
    OR (c.`VisitingPrincipalID` IS NOT NULL AND p2.`ID` IS NULL);
SET @orphans = @orphans + @n;
SELECT COUNT(*) INTO @n FROM `warehouse` c
  LEFT JOIN `warehouse` p0 ON c.`ParentID` = p0.`ID`
 WHERE  (c.`ParentID` IS NOT NULL AND p0.`ID` IS NULL);
SET @orphans = @orphans + @n;

-- Same two-row-subquery abort the sql_mode preflight uses: on the false branch the subquery
-- returns two rows, which is ERROR 1242 and stops the run before section 8 changes anything.
SELECT IF(@orphans = 0,
          CONCAT('orphan check OK - 0 rows across ', 651, ' relationships; foreign keys can be added without re-validation'),
          (SELECT CONCAT('ABORT: ', @orphans, ' rows still reference a parent that does not exist')
           UNION ALL
           SELECT 'Sections 4c/5/B were supposed to have cleaned these. Do NOT skip this check - find the rows first.')
       ) AS preflight_orphans;

-- 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 was left ON at the time, and that forced 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.
--
-- ⚠ CHANGED 2026-08-15: FOREIGN_KEY_CHECKS IS TURNED OFF FOR THIS SECTION ONLY.
--   With checks on, InnoDB cannot add a foreign key in place -- it copies the whole table
--   and re-validates every row, which is where 154 table copies came from. With checks off
--   the same ADD CONSTRAINT is metadata only.
--   The validation is NOT skipped, it MOVED: section 7b above asserts that zero orphans
--   remain across all 651 relationships, and aborts the run if any do. Checks go back
--   on immediately after this section, and @OLD_FK is still restored at the end of the file.
--   The grouping (one ALTER per table) is unchanged from the original.
-- ---------------------------------------------------------------------

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;


-- ---------------------------------------------------------------------

-- Back on for everything that follows. The restore at the end of the file sets @OLD_FK.

-- 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 32 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);
