Is there some method to make the serial number be reset automatically when it over the maximum value? (From DBMR1836)

~ 0 min
2016-03-08 07:47

By Stored Procedure and trigger can achieve that.

For example: suppose there is a table named t1: t1 (c1 serial)

[Stored Procedure]

$ create procedure sp1(char(32) tbname, int ns1); { $ begin declare section;

  char sqlstring[100];

$ end declare section;


$ begin code section;


if (ns1 >= 2147483646)


   sprintf(sqlstring, "alter table %s set serial 0", tbname);

   $ execute immediate from :sqlstring;



$ end code section;




[SQL command]

create procedure from '';

create trigger tr1 after insert on t1 for each row (call sp1('t1', new.c1));

Average rating 0 (0 Votes)

You cannot comment on this entry