I have a database on Xampp and I wish to update some tables at the same time and I wish to rollback if the value already exist in some tables.
- I have thought:
- trigger: but I don't like (because the server is not mine and so on)
- BEGIN query (to check), insert (if the condition is right) COMMIT/ROLLBACK but in this way I kill the concurrency.
Is there another way or trick in order to do it?
I wish to do this:
if(value exist) rollback;
else insert;
But I have some tables so I wish to do some like that:
if(value1 in table 1 not exist && value2 in table2 not exist)
insert;
else rollback
Another example:
Table1: dog color -> Bobby black - Rex white
Table2: pot misure -> Moon 12 - Lima 13
insert in table1 dog color Bobby pink
insert in table2 pot misure Charly 9
rollback all because in table1 already exist Bobby
- In this case I can use begin transaction and rollback:
- begin
- transaction query in order to know if field is egual
- rollback or insert commit
But I wish to find a way like that:
insert bla bla if(condition)
is it possible?
I have found this:
Insert into Table1 (dog, color) SELECT 'Zulu', 'yellow' WHERE not
exists (select * from Table1 where dog = 'Zulu')
Bu if I have some of these instructions have I use begin and commit?