opiszę mój problem tak:
- mamy tabelę produkty / tbl_products(id_p)
- mamy tabelę zamówienia / tbl_orders(id_o + FOREIGN KEY tbl_products.id_p)
Piszemy joina, który pokaże jakie zamówienie dotyczyło jakiego produktu (jedno zamówienie = jeden produkt).
Klucz obcy może usunąć każde zamówienie przypisane do produktu - rozwiążemy to przez ON DELETE NO ACTION
ale
co zrobić jeśli zostało przyjęte zamówienie, a zaraz potem usunięto produkt z bazy danych ? Jak to ładnie wyświetlić użytkownikowi ?
Pozdrawiam
Edit : mam coś takiego
Cytat
SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier specified. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported.