参考: DECLARE _item_in_used INT; SELECT COUNT(*) INTO _item_in_used FROM order_detail WHERE item_id = _item_id;/* do not update name, UI should protected changing name but we protected it again in the proc ... */ IF _item_in_used >0 THEN UPDATE items SET cat_id = _cat_id, code = _code, price = _price WHERE item_id = _item_id; ELSE UPDATE items SET cat_id = _cat_id, code = _code, name = _name, price = _price WHERE item_id = _item_id; END IF;
中间加上表名识别delete n from sort where exists(select id from sort where id=329)
非常感谢三楼得朋友,不过你那条语句应该这样写: delete n from sort as n where exists(select id from sort where id=329)
delete from sort where id=329 这样不就行了吗... delete from sort where exists(select id from sort where id=329) 这句如果sort表里存在id=329将会清空整个sort表 正确的应该是 delete from sort as s1 where exists(select id from sort where s1.id=sort.id and id=329)
DECLARE _item_in_used INT;
SELECT COUNT(*) INTO _item_in_used FROM order_detail WHERE item_id = _item_id;/* do not update name,
UI should protected changing name
but we protected it again in the proc ...
*/
IF _item_in_used >0 THEN
UPDATE items SET cat_id = _cat_id, code = _code, price = _price WHERE item_id = _item_id;
ELSE
UPDATE items SET cat_id = _cat_id, code = _code, name = _name, price = _price WHERE item_id = _item_id;
END IF;
delete n from sort as n where exists(select id from sort where id=329)
这样不就行了吗...
delete from sort where exists(select id from sort where id=329)
这句如果sort表里存在id=329将会清空整个sort表
正确的应该是
delete from sort as s1 where exists(select id from sort where s1.id=sort.id and id=329)