E
E
Edward2016-09-29 01:59:47
MySQL
Edward, 2016-09-29 01:59:47

How to stop an INSERT query if a condition is not met?

Hello. There is a table "Limit" with the structure factory, material, limit
And there is a table Shipment where requests will be entered when the factory asks to take some material. How to write a trigger to check if the request is more than the limit, then do not execute. Example of inserting into the Shipping table

INSERT INTO `Отгрузка ` (`factory`, `material`, `kol`) VALUES ( 'фабрика1', 'дерево', '127', )

but in the table the limit is Factory1= tree=100 insert example
INSERT INTO `Лимит` (`factory`, `material`, `kol`) VALUES ( 'фабрика1', 'дерево', '100', )

How to write a trigger so that the first request is not executed if there is more than the limit?
I know to use CREATE TRIGGER BEFORE, but how do I abort the insertion?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
entermix, 2016-09-29
@ed_milson

Canceling an Insert in a MySQL
MySQL Trigger. Stop sql query execution via trigger

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question