The advantage of using null foreign keys

I need to compile a table for some new components that will track available and used resources. It will be something like this:

CREATE TABLE components
(
   component_Id int NOT NULL PRIMARY KEY,
   workOrder_Id int FOREIGN KEY,
   componentSerial varchar(25) NOT NULL,
   foo varchar(50),
   bar int,
   information nvarchar(250)
   date DateTime
)

What are the benefits of making workOrderID FOREIGN KEY null if not already used, not NOT NULL and defaults to 0? For me, this means that a nullable value makes sense.

I looked at some similar situations, but I'm not sure why someone chose one of them.

+3
source share
2 answers

0, , workOrder 0, workOrder . .

(, FOREIGN KEY , , , , , , MyISAM. , FOREIGN KEY , , REFERENCES SQL.)

NULL, - workOrders UNIQUE _Id.

+9

, : , NULL " ", .

+6

Source: https://habr.com/ru/post/1761996/


All Articles