Db2 SQLCODE

SQLCODE -612: Duplicate name

SQLCODE -612 (SQLSTATE 42711) means a statement used the same name twice where names must be unique. Most often it's the same column name twice in a CREATE TABLE, CREATE VIEW, CREATE INDEX or ALTER TABLE.

Other names for this code

Also written as SQL -612, SQLCODE=-612, SQLCODE = -612, db2 -612, sqlstate 42711, SQL0612N, is a duplicate name, duplicate column name.

What it means

Column names have to be unique within a table, a view and an index. The same goes for period names in a table and for the column list of a trigger's UPDATE OF clause. When a statement repeats a name in one of those places, Db2 rejects it with -612. The message gives the repeated name.

Db2 for z/OS lists these cases.

  • An index that names the same column more than once.
  • A CREATE TABLE or ALTER TABLE that defines two columns, or two periods, with the same name, or a period with the same name as a column.
  • A PRIMARY KEY, FOREIGN KEY or UNIQUE list in CREATE TABLE that repeats a column.
  • An ALTER TABLE that names the same column in more than one clause. The only allowed pairing is ALTER COLUMN with ADD CHECK CONSTRAINT.
  • A view with two columns of the same name.
  • A trigger whose UPDATE OF list repeats a column.
  • Two arguments with the same name passed to XMLQUERY or XMLEXISTS.
  • An include column in a data change statement that clashes with a table column or another include column.

Common causes

  • A CREATE VIEW over a join selects the same column name from two tables, such as A.CUST_NO and B.CUST_NO, without renaming either.
  • A column was pasted twice into a long CREATE TABLE.
  • An ALTER TABLE changes the same column in two clauses of one statement.
  • Generated DDL repeats a column in an index or key list.
  • A new column added with ALTER TABLE ADD has the same name as a period, or the other way round.

How to find the problem

  1. Take the name from the message and search the statement for it.
  2. For a view, look at the SELECT list. Two columns with the same unqualified name are the usual cause.
  3. For ALTER TABLE, check whether the column appears in more than one clause.

How to fix it

  • In a view, rename one of the columns with AS in the SELECT list, or give the view its own column list.
  • Remove the duplicate column from the table, index or key list.
  • Split an ALTER TABLE that touches the same column twice into separate statements.
  • Rerun the corrected statement.

What it looks like

DSNT408I SQLCODE = -612, ERROR:  CUST_NO IS A DUPLICATE NAME
DSNT418I SQLSTATE   = 42711 SQLSTATE RETURN CODE

IBM documentation

IBM documentation: -612. Use the documentation for your installed release.

Report a correction to WND Software.

Questions

Why does my join work as a query but fail as a view?

A query can return two columns with the same name. A view can't, because its columns need unique names. Rename one with AS.

What is the difference between -612 and -601?

-612 is a name repeated inside one statement. -601 is a new object whose name is already used by an existing object.

Is -612 the same on Db2 for LUW?

Yes. Db2 for LUW reports SQL0612N with SQLSTATE 42711 for a duplicate name.