I have three tables so I can display separate tables and keep track of different things.
How do I make ‘pull_qty” in CARTONS_PULLED and ‘add_qty’ in CARTONS_ADDED update ‘qty’ in CARTONS _CURRENT?
When I create a new Part Number with a quantity it inserts into CARTONS_CURRENT.
Now I need to update the ‘qty” in CARTONS_CURRENT with adds and pulls from the two other tables? the ‘part_no’ is the primary key and is always the reference to update.
Here are my tables:
DATABASE NAME: _hero
TABLE NAME: CARTONS_CURRENT
+--------------+--------------+--------+--------+-------------------+------------+
| Column | Type | Null | Key | Default | Extra |
+--------------+--------------+--------+--------+-------------------+------------+
| orig_time | timestamp | No | | CURRENT_TIMESTAMP | |
| type | text | No | | | |
| part_no | varchar(20) | No | Prim | | |
| description | varchar(75) | No | | | |
| count | varchar(2) | No | | | |
| size | varchar(30) | No | | | |
| min | int(7) | No | | | |
| max | int(7) | No | | | |
| qty | int(8) | No | | | |
+--------------+--------------+--------+--------+-------------------+------------+
TABLE NAME: CARTONS_ADDED
+--------------+--------------+--------+--------+-------------------+------------+
| Column | Type | Null | Key | Default | Extra |
+--------------+--------------+--------+--------+-------------------+------------+
| add_time | timestamp | No | Prim | CURRENT_TIMESTAMP | |
| type | text | No | | | |
| part_no | varchar(20) | No | Prim | | |
| add_type | varchar(25) | No | | | |
| add_qty | int(8) | No | | | |
| add_ref | varchar(35) | No | | | |
| add_by | text | No | | | |
| add_notes | varchar(300) | No | | | |
+--------------+--------------+--------+--------+-------------------+------------+
TABLE NAME: CARTONS_PULLED
+--------------+--------------+--------+--------+-------------------+------------+
| Column | Type | Null | Key | Default | Extra |
+--------------+--------------+--------+--------+-------------------+------------+
| pull_time | timestamp | No | Prim | CURRENT_TIMESTAMP | |
| type | text | No | | | |
| part_no | varchar(20) | No | Prim | | |
| pull_type | varchar(25) | No | | | |
| pull_qty | int(8) | No | | | |
| pull_ref | varchar(35) | No | | | |
| pull_by | text | No | | | |
| pull_notes | varchar(300) | No | | | |
+--------------+--------------+--------+--------+-------------------+------------+
You’d write triggers for the
CARTONS_PULLEDandCARTONS_ADDEDtables which do the appropriate updates inCARTONS_CURRENTtable. Ie something likeif you want to add the value of
add_qtyto theCARTONS_CURRENT.qtywhen new record is inserted intoCARTONS_ADDED.