You may use trigger. But, there is another, I think better way:
- Alter Product table - add AUTO_INCREMENT property to the primary key.
- Insert new product, MySQL will generate new ID
- Get last inserted ID using last_insert_id MySQL function, and insert new record in child table
MySQL example:
CREATE TABLE Product(
Prod_id INT PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(40),
Barcode INT
);
CREATE TABLE Card(
Prod_id INT,
Price DECIMAL(8, 2),
FOREIGN KEY (Prod_id) REFERENCES Product(Prod_id)
);
INSERT INTO Product VALUES (NULL, 'phone', 1000);
INSERT INTO Card VALUES(LAST_INSERT_ID(), 10.5);
First INSERT wall add new product with autogenerated ID. The second, will get this new ID and use it for new Card record.