Question:
should i write FK, NULL or NOT_NULL?
yugi
2012-05-29 14:09:59 UTC
i'm trying to do a data dictionary and am filling the tables with ( attributes , Null, Type , length)
one of the tables i got is like


create table user(
user_number(8),
First_name varchar(30) not null,
Last_name varchar(30) not null,
DOB date not null,
nationality varchar (30)not null ,
gender char (1) not null ,
address varchar(30) not null,
Primary key(user_ID)
foreign key(profile_ID));

when i start describing them in the table it goes like

column name NULL key type ...
--------------------------------------------------------------------
user_ID null pk varchar
profile_ID null fk varchar

my question is , is it right to put both pk & fk as null?
or should i make fk Not-Null?
Three answers:
2012-05-29 14:19:56 UTC
If you are considering making either the PK or the FK null, you have some serious problems in your database design.



The primary key is the (main) field you use to sort data with, and it cannot be NULL. Depending on your RDBMS you may be able to get away with a FK being null, but it's a dumb idea. NULL is not a unqiue number, and FK's should be somewhat unique.
TheMadProfessor
2012-05-29 21:38:43 UTC
A primary key (by definition) must be non-null and unique. A field used as the target for a FK must also be unique but can be nullable. Also, even if the target column is not nullable, the foreign key reference can be.
Rahul
2012-05-29 21:14:58 UTC
you can't make primary key null and foreign key also null


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...