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 an instance database?
Explain the function done by data manager?
How do we specify index to include or not during bind process.
Mention the different locking levels that are available in db2.
What does a deadlock mean in DB2?
How do I import data from excel to db2?
What is dbrm?
What is dbrm? When it will be created?
What is db2 optimizer?
i tried to copy some records from microsoft excel to as-400 physical file through "Bosanova" emulation. Out of 14000 records only 12000 records copies and subsequently programe started to hang. Then, i closed the program forcefully. I did' under stand the problem. Also when i try to compile the physical file it is showing as "The file in use". How to overcome this problem?
How to create backup table in db2?
File not opened because library is *PROD and debug is UPDPROD(*NO). ? what may be the reason? how to solve it..?
What is drop table?
What is dpf in db2?
What is the syntax for creating a table in the db2 database?