Is it possible make constraints check on transaction level? For example, there is structure:
CREATE TABLE _users (
id INT UNSIGNED NOT NULL,
value VARCHAR(30) NOT NULL,
PRIMARY KEY (id)
) ENGINE = InnoDB;
CREATE TABLE _visits (
id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
FOREIGN KEY (user_id) REFERENCES _users (id)
) ENGINE = InnoDB;
Here is example of query, where i want to trigger fk check. Is it possible? If not, are there any other methods to make delayed check.
START TRANSACTION;
SET FOREIGN_KEY_CHECKS = 0;
INSERT INTO _visits (id, user_id) VALUES (1,1);
INSERT INTO _users (id, value) VALUES (1, 'value');
SET FOREIGN_KEY_CHECKS = 1;
-- HERE I WANT TO TRIGGER CONSTRAINT CHECKS
COMMIT;