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 null in db2?
What is the role of the data page in the db2 database?
Hi Everyone... Under the Logical files, when am working on multiple rec format logical file, I have joined two pf's using the multiple record format logical file concept, but when i run queried the LF only the first mentioned pf records are reflecting and I am not able to see any of the field records specified under the second pf. Kindly let me know whats the reason behind this. Below is the str of LF., R rec PFILE(LOGICAA) CUSTNO CUSTNAME BILL K CUSTNO R rec1 PFILE(LOGICAA1) CUSTNO ADD K CUSTNO .....
How do you concatenate the firstname and lastname from emp table to give a complete name?
How do I delete a column in db2?
Following a db2 update statement, what is the quickest way to compute the total number of updated rows?
what is utility for parm lib
What is the use of db2?
How to find the number of rows in db2 tables?
How does db2 sample database connect?
What type of database is db2?
Define sqlca.
What is check constraint. Explain with example.
What is iseries database?
Mention data types used in db2 ?