PCBA BOM Staging Table and Validation SQL Generator
Electronic BOMs from CAD or customers often arrive with quantity errors, missing manufacturer part numbers and duplicate reference designators. This generator gives you staging tables and validation queries to catch them before the data is loaded into your ERP.
Fill in
1. Create staging tables
CREATE TABLE stg.pcba_bom_line ( assy_pn VARCHAR(40) NOT NULL, assy_rev VARCHAR(10) NOT NULL, line_no INT NOT NULL, comp_pn VARCHAR(40) NOT NULL, mpn VARCHAR(80) NULL, manufacturer VARCHAR(80) NULL, qty_per DECIMAL(12,4) NOT NULL, uom VARCHAR(10) NOT NULL, dnp_flag CHAR(1) NOT NULL DEFAULT 'N', PRIMARY KEY (assy_pn, assy_rev, line_no) ); CREATE TABLE stg.pcba_bom_refdes ( assy_pn VARCHAR(40) NOT NULL, assy_rev VARCHAR(10) NOT NULL, line_no INT NOT NULL, ref_des VARCHAR(20) NOT NULL, PRIMARY KEY (assy_pn, assy_rev, ref_des) );
2. Insert example rows
INSERT INTO stg.pcba_bom_line (assy_pn, assy_rev, line_no, comp_pn, mpn, manufacturer, qty_per, uom, dnp_flag)
VALUES ('PCBA-10452', 'B', 10, 'CAP-0402-100NF', 'GRM155R71C104KA88D', 'Murata', 3, 'EA', 'N');
INSERT INTO stg.pcba_bom_refdes (assy_pn, assy_rev, line_no, ref_des)
VALUES ('PCBA-10452', 'B', 10, 'C1'), ('PCBA-10452', 'B', 10, 'C2'), ('PCBA-10452', 'B', 10, 'C3');3. Check: quantity does not match reference designator count
SELECT l.line_no, l.comp_pn, l.qty_per, COUNT(r.ref_des) AS refdes_count FROM stg.pcba_bom_line l LEFT JOIN stg.pcba_bom_refdes r ON r.assy_pn = l.assy_pn AND r.assy_rev = l.assy_rev AND r.line_no = l.line_no WHERE l.assy_pn = 'PCBA-10452' AND l.assy_rev = 'B' AND l.dnp_flag = 'N' GROUP BY l.line_no, l.comp_pn, l.qty_per HAVING COUNT(r.ref_des) <> l.qty_per;
4. Check: component used on lines with no manufacturer part number
SELECT line_no, comp_pn FROM stg.pcba_bom_line WHERE assy_pn = 'PCBA-10452' AND assy_rev = 'B' AND (mpn IS NULL OR mpn = '' OR manufacturer IS NULL OR manufacturer = '');
5. Check: same component number listed on more than one line
SELECT comp_pn, COUNT(*) AS line_count, SUM(qty_per) AS total_qty FROM stg.pcba_bom_line WHERE assy_pn = 'PCBA-10452' AND assy_rev = 'B' GROUP BY comp_pn HAVING COUNT(*) > 1;
Table and column names here are generic staging names, not those of a specific ERP. Adjust data types and syntax for your database (SQL Server, Oracle, PostgreSQL) and map the clean data to your ERP's BOM import tool or API. Test in a non production system first.
BOM clean up before ERP load
We can review your BOM data quality checks and import approach.
Optional. The tool and every export work without this. No spam.
How to use the generator
Enter the schema, assembly number and revision, then copy the blocks in order. Create the staging tables, load the BOM lines and the reference designators from your spreadsheet using your database import tool, then run the check queries. Fix the rows they return in the staging data, not in the ERP, so you keep a clean audit trail of what changed before the load.
Why these checks matter
A BOM line quantity that does not match the count of reference designators is one of the most common causes of line shortages and wrong builds. Missing manufacturer part numbers break approved vendor list checks. Duplicated component lines inflate or fragment purchasing demand. The primary key on the reference table blocks a designator from appearing twice on the same revision.
- Run checks per assembly revision
- Exclude do not populate lines from count checks
- Keep the staging tables after the load as evidence
Worked example
A capacitor line shows quantity 4 but only three reference designators are listed. The check query returns the line with refdes_count 3. The engineer finds that C4 was dropped from the CAD export, corrects the staging row and re-runs the check until the query returns nothing.
Common mistakes
People often load straight into the ERP and rely on its import errors, which seldom explain engineering data problems. Others forget that alternates and substitutes belong on a separate structure, not on additional BOM lines. Do not treat fitted and unfitted lines the same; use the do not populate flag and exclude those lines from the count.
Frequently Asked Questions
Does this work with my ERP table names?
The tables are generic staging names so you can use them with any ERP. After validation, map the clean data to your ERP's own BOM import tool, service or API.
Which databases does the SQL work on?
The statements are standard SQL and work on SQL Server, PostgreSQL and Oracle with minor type changes. For example, Oracle uses VARCHAR2 and NUMBER.
How do I handle alternates and approved manufacturers?
Keep them in a separate table linked by component number, with one row per approved manufacturer part number. Do not duplicate the BOM line.
Can I use it for engineering change orders?
Yes. Load the new revision into the staging tables under its own revision key and compare it with the previous revision to list added, removed and changed lines.
Netray can help build and run BOM validation against your ERP's real tables and import tools as part of a migration or NPI process.
Related Tools
Pick and Place Centroid File Converter Script Generator (Python)
Fill a few fields and get a Python script that reads a centroid CSV, applies offsets and writes a machine ready file.
Engineering & PLMPCBA Engineering Change Notice Template
A fill-in ECN for PCB assembly changes covering BOM, fabrication data, process impact, inventory disposition and approvals.
Electronics ManufacturingPCB Assembly Cost Estimator
Estimate SMT and through-hole assembly cost per board and total order cost from placements, complexity, NRE, and test overhead.
Supply Chain & InventorySMT Reel and MOQ Buy Quantity Calculator
See how minimum order quantity and reel size change what you actually buy, how much excess you hold and what it costs to carry.
More Developer Tools tools
See all- Component Shortage SQL Query Generator (Open Demand vs Supply)
- BOM Scrub Python Script Generator (Duplicate MPN, Missing RefDes, Qty Mismatch)
- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)
- SAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
- SAP ABAP Open Items SELECT Generator
- SAP ACDOCA SQL Query Generator
- SAP QM Inspection Lot ABAP SELECT Generator
- SAP Quality Notification Pareto SQL Query Generator
- SAP QM Usage Decision BAPI Skeleton