Search code examples
databaserelational-databaseprimary-keycandidate-key

Can prime attributes have null values?


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,


Solution

  • 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.)

    Schemas and keys

    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.