我在Xampp上有一个数据库,我希望同时更新一些表,并且如果某些表中已经存在该值,我希望回滚。
有其他方法或技巧可以做到吗?
我想这样做:
if(value exist) rollback;
else insert;
但是我有一些桌子,所以我希望这样做:
if(value1 in table 1 not exist && value2 in table2 not exist)
insert;
else rollback
另一个例子:
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
全部回滚,因为表1中已经存在Bobby
但是我希望找到这样一种方式:
insert bla bla if(condition)
有可能吗?
我发现了这个:
Insert into Table1 (dog, color) SELECT 'Zulu', 'yellow' WHERE not
exists (select * from Table1 where dog = 'Zulu')
如果我有这些说明,我可以使用begin和commit吗?