DB2 SQL Errors Codes and Error Messages and Warnings from Error -157 to -159

SQLServerF1

Error: DB2 SQL Error: SQLCODE=-157, SQLSTATE=42810, SQLERRMC=TBSPACEID=, TABLEID=, COLNO=, DRIVER=
ONLY A TABLE NAME CAN BE
SPECIFIED IN A FOREIGN KEY
CLAUSE. object-name IS NOT THE
NAME OF A TABLE.
Explanation: The indicated object was identified in a
FOREIGN KEY clause of a CREATE or ALTER TABLE
statement. A FOREIGN KEY clause must identify a
table.
System action: The statement cannot be executed.
Programmer response: Correct the statement to
specify a table name in the foreign key clause.
SQLSTATE: 42810

Error: DB2 SQL Error: SQLCODE=-158, SQLSTATE=42811, SQLERRMC=TBSPACEID=, TABLEID=, COLNO=, DRIVER=
THE NUMBER OF COLUMNS
SPECIFIED FOR THE VIEW OR TABLE
IS NOT THE SAME AS THE NUMBER
OF COLUMNS SPECIFIED BY THE
FULLSELECT, OR THE NUMBER OF
COLUMNS SPECIFIED IN THE
CORRELATION CLAUSE IN A FROM
CLAUSE IS NOT THE SAME AS THE
NUMBER OF COLUMNS IN THE
CORRESPONDING TABLE, VIEW,
TABLE EXPRESSION, OR TABLE
FUNCTION
Explanation: One of the following situations has
occurred:
v The number of column names that are specified for a
view in a CREATE VIEW statement is not the same
as the number of elements that are specified in the
SELECT clauses of the fullselect that follows. These
elements might be column names, SQL functions,
and expressions, for example.
v The number of column names that are specified for a
table in a CREATE TABLE statement is not the same
as the number of columns in the result table of the
fullselect that follows.
v The number of column names that are specified in a
correlation clause is not the same as the number of
columns in the corresponding table, view, table
expression, or table function.
v The number of column names that are specified in a
column list of a common table expression is not the
same as the number of elements specified in the
fullselect.
System action: The statement cannot be processed.
Programmer response: Specify a column name for
each column in the result, and try the request again.
SQLSTATE: 42811

Error: DB2 SQL Error: SQLCODE=-159, SQLSTATE=42809, SQLERRMC=TBSPACEID=, TABLEID=, COLNO=, DRIVER=
THE STATEMENT REFERENCES
object-name WHICH IDENTIFIES AN
object-type RATHER THAN AN
expected-object-type
Explanation: The object object-name was specified as
part of a statement, and refers to an object of type
object-type instead of the expected type
expected-object-type. The type of the object that is
provided with the statement must match the type that
is identified by expected-object-type. For example, if the
statement is DROP ALIAS TED.T1, then TED.T1 must
be an alias name.
If object-type or expected-object-type is TABLE, and
object-type or expected-object-type is a particular type of
table, then the type of table was not valid for the
statement that was specified.
System action: The statement cannot be executed.
Programmer response: Change the statement to match
the type of object that is identified by
expected-object-type. For example:
v An ALTER VIEW statement must reference an
existing view.
v A COMMENT ON ALIAS statement must specify the
name of an alias, and not the name of a table or
view.
v A COMMENT ON TABLE statement must reference
an existing table or view.
v A CREATE INDEX statement with the UNIQUE
keyword must specify a table that is not a
materialized query table.
v A CREATE INDEX statement must specify the name
of a table that is not a clone table.
v A CREATE TRIGGER statement must specify a table
in the ON clause that is not a materialized query
table. That is, a trigger cannot be defined for a
materialized query table.
v A CREATE TRIGGER statement must specify the
name of a table that is not a clone table.
v A DROP ALIAS statement must specify the name of
an alias, and not the name of a table or view.
v A DROP TABLE statement must reference an existing
table. If an alias is specified, then the table that the
alias refers to is dropped. Use the DROP ALIAS
statement to drop the alias.
v A DROP VIEW statement must reference an existing
view.
v A REFRESH TABLE statement must refer to a
materialized query table.
SQLSTATE: 42809

Above are list of DB2 SQL Errors and Warnings from Error -157 to -159 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 *