I understand that a candidate key can not have NULL values. But a candidate key can itself be a combination of many attributes which are called prime attributes. Can these prime attributes have NULL as a value?
Regards,
I understand that a candidate key can not have NULL values. But a candidate key can itself be a combination of many attributes which are called prime attributes. Can these prime attributes have NULL as a value?
Regards,
Prime attribute An attribute which appears as an attribute for some candidate key. (It needn't be the primary key, or even any key of interest.)
Prime attributes are part of a candidate key. A candidate key, as the name suggests, is a candidate for primary key. That means, a candidate key can become a primary key, if required.
Now if you recall, any primary key cannot be null. So, by definition, a prime attribute cannot be null. If it is null, it ceases to be a prime attribute.
Here is an explanation.
If you have a composite candidate key lets say
CK1(P1, P2)
P1 and P2 are a prime attributes. You can set P1 or P2 as null, because there is no constraint on prime attributes other than those of primary key attributes.
So,
CK1(P1, P2=null)
Now, CK1 cannot be a primary key, hence is no more a candidate key and hence, P2 is no more a prime attribute.
I believe it depends on the database you use.
For example, you don't have to do it explicitly in MySQL. This is defined in the manual:
A PRIMARY KEY is a unique index where all key columns must be defined as NOT NULL. If they are not explicitly declared as NOT NULL, MySQL declares them so implicitly (and silently).