如何设置初始发电机值? [英] How to set initial generator value?

查看:74
本文介绍了如何设置初始发电机值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将新的Firebird生成器/序列初始化为现有旧"表的最大主键值.我尝试了以下操作,但不起作用,出现错误令牌未知-第6行,第8列,选择".我不能手动执行此操作,因为它必须在许多不同的DB上执行.我正在使用Firebird 2.5.1.

I need to initialise a new Firebird generator / sequence to the max primary key value of an existing, 'old' table. I tried the following but it is not working, I get the error "Token unknown - line 6, column 8 select". I cannot do this manually as it must be executed on many different DBs. I am using Firebird 2.5.1.

根据 http://www.firebirdsql. org/file/documentation/reference_manuals/reference_material/html/langrefupd25-execblock.html 应该可以工作-我在做什么错?

According to http://www.firebirdsql.org/file/documentation/reference_manuals/reference_material/html/langrefupd25-execblock.html this should work - what am I doing wrong?

set term #;  
execute block  
as  
declare i int = 0;  
begin  
   i = select max(ID) from OrganizationType_OLU;  
    alter sequence OrganizationType_OLU restart with :i;  
end  
#  
set term ;# 

推荐答案

set term #;
execute block    
as  
declare i int = 0;    
declare temp int = 0;
begin  
  i = (select max(id) from items);  
  temp = gen_id(GEN_ITEMS_ID,-(gen_id(GEN_ITEMS_ID,0))); ---set some_gen to 0  
  temp = gen_id(GEN_ITEMS_ID,:i);  --- set to i
end #  
set term ;#

这篇关于如何设置初始发电机值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆