Domanda

After truncating table, and inserting new values in table, auto-increment values are not set to started value 1. When inserting new values it's remember last index-ed value of auto-increment.

Colum in table named: ID

Index: PRIMARY,

Initial Value: 1

Cache size: 1

Increment: 1

[checked on IBM DB2 Control Center]

This query:

TRUNCATE TABLE ".$this->_schema.$table." DROP STORAGE IGNORE DELETE TRIGGERS IMMEDIATE

table is EMPTY.

After INSERT NEW VALUES example: INSERT INTO DB2INST1.db (val) VALUES ('abc') it's INSERT with LAST

ID | val

55 | abc

But it SHOULD BE:

ID | val

1  | abc
È stato utile?

Soluzione

I'm guessing here that your question is "how do you restart the IDENTITY sequence?" If that is the case, then you can reset it with the following SQL:

ALTER TABLE <table name> ALTER COLUMN <IDENTITY column> RESTART WITH 1

However, like @Ian said, what you are seeing is the expected behavior of a TRUNCATE.

Altri suggerimenti

First select in TABLE SCHEMA WHERE is name of IDENTITY column:

Query 1:

SELECT COLNAME FROM SYSCAT.COLUMNS WHERE TABSCHEMA = 'DB2INST1' AND TABNAME = 'DB' AND IDENTITY = 'Y'

Then, truncate table and return it's example: ID for altering index:

Query 2:

This ID puts on query for reset and altering index identity:

ALTER TABLE DB2INST1.DB ALTER COLUMN ID RESTART WITH 1

Change ID above returned from Query 1, which returns name of ID to Query 2.

SOLVED!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top