Selected text from the Create Table page of the
SQLCE Books On Line:
All columns defined within a PRIMARY KEY
constraint must be defined as NOT NULL. If nullability is not specified, all
columns participating in a PRIMARY KEY constraint have their nullability set to
NOT NULL.
All columns defined as a UNIQUE constraint
must be defined as NOT NULL. If nullability is not specified, all columns
defined as UNIQUE constraints have their nullability set to NOT NULL.
Is a constraint that provides referential integrity
for the data in the column. FOREIGN KEY constraints require that each value in
the column exists in the specified column in the referenced table.
FOREIGN KEY Constraints
When a value
other than NULL is entered into the column of a FOREIGN KEY constraint, the
value must exist in the referenced column; otherwise, a foreign key violation
error message is returned.
FOREIGN KEY constraints can reference only tables within
the same database.
FOREIGN KEY constraints can reference
another column in the same table (a self-reference). However, FOREIGN KEY
constraints cannot be used to create a self-referencing or circular FOREIGN KEY
constraint with the CASCADE option.
The REFERENCES clause of a
column-level FOREIGN KEY constraint can list only one reference column, which
must have the same data type as the column on which the constraint is
defined.
The REFERENCES clause of a table-level FOREIGN KEY
constraint must have the same number of reference columns as the number of
columns in the constraint column list. The data type of each reference column
also must be the same as the corresponding column in the column
list.
FOREIGN KEY constraints can reference only columns
in PRIMARY KEY or UNIQUE constraints in the referenced table.
So, the jist of this leads me to ask, how can you put a NULL
value in a Foreign Key column? According to the above, there is no way to do
this. Why? Because you cannot put a NULL in a Primary or Unique key. The value
must exist in the PK or UK for there to be a value in the FK. PK or UK do not
allow a value of NULL, so that cannot be a value of the FK either.
My recollection, and I am not sure of this, is that SQL Server
will allow one Null per column. SQL CE does not do this.
Also curious how you get a Null value in a column specified as
Not Null.