문제

Is it possible to make the following two queries to one single query?

update customers set customer_name = 'John'  where customer_id=1;

update purchases set state='Accepted'  where customer_id=1;

customer (table)

customer_id(PK)
customer_name

purchases (table)

customer_id(FK)
product
state

Thanks

도움이 되었습니까?

해결책

You can execute them in a single transaction:

START TRANSACTION;
update customers set customer_name = 'John'  where customer_id=1;
update purchases set state='Accepted'  where customer_id=1;
COMMIT;

If something fail inside the transaction all changes are rolled back

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top