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?
Answers were Sorted based on User's Feedback
Answer / sangeetha
There cannot be null values in a Primary Key column.
It will result in error code.
| Is This Answer Correct ? | 26 Yes | 3 No |
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 |
Answer / satya prasad n
The PRIMARY KEY cannot be null. you can insert ZERO into
that but should not be null. It will throw an error if you
try to inserts a NULL.
| Is This Answer Correct ? | 8 Yes | 4 No |
Answer / guest
A primary key can have a NULL value. The error will be
shown only when NOT NULL is defined in the table creation.
| Is This Answer Correct ? | 10 Yes | 10 No |
Answer / sachin borase
May be it will throws the -803 error (803 means index
violation )
| Is This Answer Correct ? | 1 Yes | 4 No |
Answer / priya
Can you please clarify what kind of error code/sqlcode will
be returned if we try to insert a null value in a primary
key using a DB2 insert query?
| Is This Answer Correct ? | 2 Yes | 7 No |
What is JOIN and different types of JOIN.
How can record locking be achieved in those DB2 versions which do not support it?
I have a subprogram B calling from mainprogram A.I have opened a cursor in A ,Can i fetch the same cursor in subprogram B , If yes , Please explain the reason?
How does a cursor work?
Is Cursor exicutable ?
how can u retrieve the data from null values using applicaion program.
How to access db2 tables in mainframe?
If a table has a column "dept" (declared to have nulls) and there are 10 rows in the table of which 3 have a null value in the dept column, what will select count(*) and select count(distinct dept) return?
wht are the restrictions for union ?
What is the role of the data page in the db2 database?
How do run the JCL which has 25 steps by skipping the following steps 5, 10,15 and 25 without using COND statement
What is buffer pool?