如果条目不存在,我想将数据插入到多个表中.
在我的情况下,我有一个餐厅餐桌,一个位置表,一张foodtype桌子和一些帮助表,如restaurant_location和restaurant_foodtype.现在我想插入一个新的餐厅条目,如果条目不存在,则填写位置和食物类型信息.
所以类似于:
IF NOT (select 1 from restaurant where name='restaurantname') THEN
INSERT INTO restaurant(x,y) VALUES (valuex,valuey);
INSERT INTO restaurant_location(rest_id,..) VALUES (rest_id,..);
INSERT INTO restaurant_foodtype(rest_id,..) VALUES (rest_id,..);
...
END IF
Run Code Online (Sandbox Code Playgroud)
我怎么能用简单的SQL做到这一点?