如何在DB2中创建ROWID列?

时间:2016-06-08 14:03:03

标签: db2

我试过了:

  CREATE TABLE rowid_type
  (
  col1 ROWID NOT NULL GENERATED ALWAYS,
  col2 int
  );

错误:

  

错误:DB2 SQL错误:SQLCODE = -104,SQLSTATE = 42601,SQLERRMC = GENERATED ALWAYS; col1 ROWID NOT NULL;,DRIVER = 4.14.111

     

SQLState:42601

     

ErrorCode:-104

修改

我提到了这个链接 - https://www.ibm.com/support/knowledgecenter/en/SSEPEK_10.0.0/com.ibm.db2z10.doc.apsg/src/tpc/db2z_specifydirectrowaccess.html?view=embed

它显示:

CREATE TABLE EMPLOYEE
  (EMP_ROWID   ROWID NOT NULL GENERATED ALWAYS,
   EMPNO       SMALLINT,
   NAME        CHAR(30),
   SALARY      DECIMAL(7,2),
   WORKDEPT    SMALLINT);

EDIT2

  • 产品名称:DB2 / LINUXX8664
  • 版本:10.5.0.5

1 个答案:

答案 0 :(得分:1)

[我的回答适用于DB2 LUW,问题已经更新,现在指向DB2 for z / OS]

尝试这样的事情:

CREATE TABLE rowid_type
(
  col1 int NOT NULL GENERATED ALWAYS AS IDENTITY,
  col2 int
);

还有更多选项可用,例如设置开始值和停止值。有关详细信息,请参阅DB2 docs on identity columns