DB2 SQL Errors Codes and Error Messages and Warnings from Error -539 to -542

SQLServerF1

Error: DB2 SQL Error: SQLCODE=-539, SQLSTATE=42888, SQLERRMC=TBSPACEID=, TABLEID=, COLNO=, DRIVER=
TABLE table-name DOES NOT HAVE A
PRIMARY KEY
Explanation: DB2 cannot perform the CREATE or
ALTER TABLE statement because the indicated table
does not have a primary key. Thus, the primary key
cannot be dropped, or the table cannot be defined as a
parent in a referential constraint.
System action: The statement cannot be processed.
Programmer response: Correct the statement to
reference a table with a primary key, or define a
primary key with ALTER TABLE ADD PRIMARY KEY
before referencing the table in a FOREIGN KEY clause.
SQLSTATE: 42888

Error: DB2 SQL Error: SQLCODE=-540, SQLSTATE=57001, SQLERRMC=TBSPACEID=, TABLEID=, COLNO=, DRIVER=
THE DEFINITION OF TABLE table-name
IS INCOMPLETE BECAUSE IT LACKS
A PRIMARY INDEX OR A REQUIRED
UNIQUE INDEX
Explanation: An attempt was made to use table
table-name in a CREATE or ALTER statement to define a
foreign key or a clone table, or it was referenced in an
SQL manipulative statement. However, the current
status of the table is incomplete, so it cannot be used as
specified. The definition of the table may be incomplete
because the table was defined with a PRIMARY KEY
clause, a UNIQUE clause, or a ROWID column with
the GENERATED BY DEFAULT attribute. The
definition of the table is incomplete, and it cannot be
used until a unique index is defined for:
v the primary key (the primary index)
v a ROWID column
v for each set of columns in any UNIQUE clause (the
required unique indexes).
An attempt was made to use the table in a FOREIGN
KEY clause or in an SQL manipulative statement.
System action: The statement cannot be executed.
Programmer response: Define a primary index or a
required unique index on the table before referencing it.
SQLSTATE: 57001

Error: DB2 SQL Error: SQLCODE=-542, SQLSTATE=42831, SQLERRMC=TBSPACEID=, TABLEID=, COLNO=, DRIVER=
column-name CANNOT BE A COLUMN
OF A PRIMARY KEY, A UNIQUE
CONSTRAINT, OR A PARENT KEY
BECAUSE IT CAN CONTAIN NULL
VALUES
Explanation: The code is used to report that a column
identified in a PRIMARY KEY, a UNIQUE constraint
clause, or a parent key (via a REFERENCES clause) is
defined to allow null values.
System action: The statement cannot be executed.
Programmer response: In the case of a column
identified in a PRIMARY KEY or a UNIQUE constraint
clause, correct the statement and rerun it.
In the case of a column identified in a REFERENCES
clause, drop the parent table then recreate it with
referenced columns defined as NOT NULL. Afterwards,
rerun the statement.
SQLSTATE: 42831

Above are list of DB2 SQL Errors and Warnings from Error -539 to -542 received while performing certain operation against DB2 Database or related products.

SQLCODE – Regardless of whether the application program provides an SQLCA or a stand-alone variable, SQLCODE is set by DB2 after each SQL statement is
executed. DB2 conforms to the ISO/ANSI SQL standard as follows:
If SQLCODE = 0, execution was successful.
If SQLCODE > 0, execution was successful with a warning.
If SQLCODE < 0, execution was not successful.
SQLCODE = 100, “no data” was found. For example, a FETCH statement returned no data because the cursor was positioned after the last row of the result table.

SQLSTATE – SQLSTATE is also set by DB2 after the execution of each SQL statement. Thus, application programs can check the execution of SQL statements by testing SQLSTATE instead of SQLCODE.

Hope this was helpful.

Thanks,
SQLServerF1 Team
Information about DB2 SQL Error Codes and Error Messages on Windows, Linux and Z/OS Operating Systems.

 

Leave a Reply

Your email address will not be published. Required fields are marked *