Can a primary key have null values? If we try to insert a
null value in a primary key column, will it work or give an
error code?
Answer Posted / ratheesh nellikal
In DB2 you can not create a primary key on a column which
is not 'not null'.
If you are trying to create a primary key on a column which
is not 'not null' then dbb2 will return an error like this
SQL0542N "feild_name" cannot be a column of a primary key
or unique key because it can contain null values.
SQLSTATE=42831
But once u alter the table and set the column to 'NOT NULL'
then you can make it as primary key.
Now if u r trying to insert an null value to ur primary key
column then db2 will trows an error like
SQL0407N Assignment of a NULL value to a NOT NULL
column "TBSPACEID=5, TABLEID=404, COLNO=0" is not allowed.
SQLSTATE=23502.
In short you can not make a column which can hold 'NULL'
value as your primary key and you can not insert a 'NULL'
value into your primary key feild.
Cheers,
Ratheesh Nellikal
| Is This Answer Correct ? | 7 Yes | 1 No |
Post New Answer View All Answers
What is copy pending status in db2?
What r the comman abends in db2, jcl and cobol???????
Explain about rct.
How does cobol compile db2 program?
What is ibm db2 used for?
How many types of page locks can be held in db2?
What is the max length of sqlca?
How do you concatenate the firstname and lastname from emp table to give a complete name?
How to access db2 tables in mainframe?
Is it possible to create an Instance in DB2 using DB2 Control Center ?
Why do we need reorg in db2?
What types of tables are there in the db2 database?
How and when does the db2 enforces the unique key?
What are host variables in db2?
What is load utility in db2?