DELETE removes the rows that match a WHERE condition:
DELETE FROM product WHERE code = 'P03';
Only the matching rows are removed; the table and its other rows stay.
Like UPDATE, a DELETE with no WHERE hits every row:
DELETE FROM product; -- empties the whole table!
Always check your WHERE before running a DELETE. The checker runs your DELETE, then reads the table back to confirm the right row is gone.
Question. Cara (customer 3) closes the account. Remove Cara and Cara's orders.
Answer. Each of Cara's orders refers to customer 3 through the foreign key customer_id. Deleting the customer first would leave orders that point at nobody, which breaks referential integrity. So remove the orders first:
DELETE FROM orders WHERE customer_id = 3;
and then the customer:
DELETE FROM customer WHERE id = 3;
Orders 12 and 13 are gone; orders 10 and 11 (Ada's) are still there.
- There is no
*inDELETE.DELETE * FROM productis a syntax error; writeDELETE FROM product WHERE …. DELETEremoves rows,DROP TABLEremoves the table. AfterDELETE FROM productthe empty table is still there.- Test a risky delete first as a
SELECTwith the sameWHERE, and check which rows it shows.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
product 테이블에서 코드 'P03'인 제품을 삭제하십시오. (이후에는 P01와 P02만 남습니다.)
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
삭제는 어떤 조건에도 사용할 수 있습니다. WHERE price < 2.00을 사용하여 가격이 2.00 미만인 모든 제품을 제거하십시오. 펜(0.80)만 사라지므로, 남은 행이 무엇인지 확인하십시오.
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
'2024-03-01' 이전에 placed된 모든 주문을 삭제하십시오. 'YYYY-MM-DD'로 작성된 날짜는 <과 올바르게 비교됩니다.
출력을 보려면 '실행'을 클릭하세요.