I have a main table called results
. E.g.
CREATE TABLE results (
r_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
r_date DATE NOT NULL,
system_id INT NOT NULL,
FOREIGN KEY (system_id) REFERENCES systems(s_id) ON UPDATE CASCADE ON DELETE CASCADE
);
The systems table as:
CREATE TABLE systems (
s_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
system_name VARCHAR(50) NOT NULL UNIQUE
);
I'm writing a program in Python with MySQL connector. Is there a way to add data to the systems
table and then auto assign the generated s_id
to the results
table?
I know I could INSERT
into systems
, then do another call to that table to see what the ID is for the s_name
, to add to the results
table but I thought there might be quirk in SQL that I'm not aware of to make life easier with less calls to the DB?