Quantcast
Channel: Nullable Foreign Key bad practice? - Stack Overflow
Browsing all 12 articles
Browse latest View live

Answer by Stephen S. for Nullable Foreign Key bad practice?

You could always add an artificial row to your Customer table, something like Id=-1 and CustomerName = 'Unknown' and then in cases when you would normally set your CustomerId in Order NULL set it to...

View Article



Answer by danny117 for Nullable Foreign Key bad practice?

Yes theres something wrong. Its not a foreign key if its nullable. Its database design by code. Maybe you make a zero link to unassigned. or "Unassigned" if your using a character col. Keep the...

View Article

Answer by Erwin Smout for Nullable Foreign Key bad practice?

Nullable columns can be in 1NF through 5NF, but not in 6NF according to what I've read.Only if you know better than Chris Date "what first normal form really means". If x and y are both nullable, and...

View Article

Answer by Walter Mitty for Nullable Foreign Key bad practice?

Optional relationships are definitely possible in the relational model. You can use nulls to express the absence of a relationship. They are convenient, but they will cause you the same headaches that...

View Article

Answer by Mark Green for Nullable Foreign Key bad practice?

If you are only adding the order temporarily with no customer id until a customer is defined, would it not be simpler to add the customer and order in a single transaction, thereby removing the need...

View Article


Answer by Bryan McLemore for Nullable Foreign Key bad practice?

I've heard it argued that Nullable columns in general are break the first degree of normalization. But in practice it's very practical.

View Article

Answer by Patrik Hägne for Nullable Foreign Key bad practice?

Having the link table is probably a better option. At least it does not violate normalization BCNF (Boyce-Codd normal form). however I would favor being pragmatic. If you have very few of these null...

View Article

Answer by matpie for Nullable Foreign Key bad practice?

Using NULL would be a good way to clean up incomplete orders:SELECT * FROM `orders`WHERE `started_time` < (UNIX_TIMESTAMP() + 900) AND `customer_id` IS NULLThe above would show orders older than 15...

View Article


Answer by Charles Bretana for Nullable Foreign Key bad practice?

No There is nothing wrong with Nullable FKs. This is common when the entity the FK points to is in a (zero or one) to (1 or many) relationship with the primary Key referenced table.An example might be...

View Article


Answer by Henning for Nullable Foreign Key bad practice?

Nullable FKs for optional many-to-one relations are totally fine.

View Article

Answer by pedromarce for Nullable Foreign Key bad practice?

I can't see anything wrong with that it is just an optional n-1 relationship that will be represented with a null in the foreign-key. Otherwise if you put your link table then you'll have to manage...

View Article

Nullable Foreign Key bad practice?

Let's say you have a table Orders with a foreign key to a Customer Id. Now, suppose you want to add an Order without a Customer Id, (whether that should be possible is another question) you would have...

View Article
Browsing all 12 articles
Browse latest View live




Latest Images