Tukkan
Tukkan

Reputation: 1625

Deleting records with foreign keys

I have a little question about deleting records with foreign keys. The problem is that, at the start I thought it is really helpful using foreign keys but when i used them it is really problematic for me. For example: I created Two tables:

Pizza: id, name, price
Order: id_Pizza (Foreign Key), address, telephone, date

All the time a client makes an order there is created record with ID of pizza ordered. Suppose that i have had 2000 orders of pizza Margherita (id=1), so i have 2000 records with id_Pizza = 1. Now I need to delete margherita from my menu because I no longer want to sell that type of pizza but i cant, because it is used as Foreign Key in Table Orders.

How to manage that problem?

Upvotes: 2

Views: 201

Answers (1)

amphibient
amphibient

Reputation: 31212

Never delete the row--instead introduce an active bit not null column and display on the menu only the table entries that have active=1.

Darn, i'm hungry now...

Upvotes: 2

Related Questions