Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

Manually Reset/Reload sequence number

$
0
0

I would like to know if there is a way to reload the next available number in a sequence.

I want to do mass importation of data in my schema after it has been created.I import data from another database and put that into hana. I cannot use the schema next value for the key because it is irrelevant and wrong : if my source database start at 10, and skip to 12 and the follow to 13, that's the key that I want in Hana.

After the importation, the problem is that the sequence stays at the same value and fail because of unique constraint of the primary key.

 

 

Examples are always good to understand and reproduce :

 

--Create the database structure

 

create table seqtable (idkey int primary key);

 

--sequence example taken from sap hana reference guide

create sequence sq_table reset by select ifnull(max(idkey), 0) +1 from seqtable;

 

--Data import. Import any value from a source system.

insert into seqtable values (1);

insert into seqtable values (2);

insert into seqtable values (3);

insert into seqtable values (4);

 

 

--Data Import finished.

 

--Start using the database for new records

 

insert into seqtable values (sq_table.nextval);

 

Could not execute 'insert into seqtable values (sq_table.nextval)'

[301]: unique constraint violated: Table(SEQTABLE), Index(_SYS_TREE_RS_#1378238_#0_#P0)

 

 

the sq_table sequence return 1, then 2, 3,4 and they all fail the primary key constraint.

I want a way to say to the sequence : reset yourself. Do your Reset cause  by query to get the next available number.

According to the reference guide, I can restart the database ... but this is not a good solution for many reasons.

 

 

 

http://help.sap.com/hana/html/sql_create_sequence.html

 

RESET BY

During the restart of the database, database automatically executes the RESET BY statement and the sequence value is restarted with the specified value from the statement after RESET BY.

If RESET BY is not specified, the sequence value is stored persistently in database. During the restart of the database, the next value of the sequence is generated from the saved sequence value.

 

Any idea ?


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>