简体   繁体   English

sybase中提交事务的临时表

[英]Temporary table committing the transaction in sybase

I am doing a bulk insert using sybase temporary table approach (# table name).我正在使用 sybase 临时表方法(#表名)进行批量插入。 This happens in a transaction.这发生在事务中。 However this operation is committing the data transaction.但是,此操作正在提交数据事务。 ( I am not doing a connection.commit myself). (我没有做一个connection.commit自己)。 I don't want this commit to happen since I might have to roll back the entire transaction later on.我不希望这种提交发生,因为我以后可能不得不回滚整个事务。 Any idea why insert using temp table is committing the transaction withought being asked?.知道为什么使用临时表插入是在不被询问的情况下提交事务吗? How do I fix this issue?我该如何解决这个问题?

The sql is something like sql 类似于

select * into #MY_TABLE_BUFFER from MY_TABLE where 0=1; 
load table #MY_TABLE_BUFFER from 'C:\temp\123.tmp' WITH CHECKPOINT ON; 
insert into MY_TABLE on existing update select * from #MY_TABLE_BUFFER; 
drop table #MY_TABLE_BUFFER; 

And I am using statement.executeUpdate() to execute it我正在使用statement.executeUpdate()来执行它

Figured out that its due to temp table not participating in transaction and doing a commit.发现这是由于临时表没有参与事务并进行提交。 Is there any workaround for this?有什么解决方法吗?

Sybase is funny about using user-specified (aka explicit) transactions in conjunction w/ the use of #temp tables (where the temp table is created while in the transaction ). Sybase 将用户指定(又名显式)事务与 #temp 表(临时表在事务中创建)结合使用很有趣。 For better or worse, Sybase considers the creation of a #temp table (including via 'select into' statement) to be a DDL statement in the context of tempdb.无论好坏,Sybase 都将创建#temp 表(包括通过'select into' 语句)视为tempdb 上下文中的DDL 语句。 In the editor, w/ default server/db settings, you'll get an error when you do this.在带有默认服务器/数据库设置的编辑器中,执行此操作时会出现错误。

As a test, you could try setting the 'ddl in tran' setting (in the context of the tempdb database) to true.作为测试,您可以尝试将“ddl in tran”设置(在 tempdb 数据库的上下文中)设置为 true。 Then, see if the behavior changes.然后,看看行为是否改变。

Note, however, that permanently leaving that setting in place is a bad idea (per Sybase documentation).但是请注意,永久保留该设置是一个坏主意(根据 Sybase 文档)。 I'm proposing it for investigative purposes only.我提议它仅用于调查目的。

The real solution (if my assumption of the problem is correct) likely lies in creating the #temp table first, then beginning the transaction, to avoid any DDL stmts in the scope of the transaction.真正的解决方案(如果我对问题的假设是正确的)可能在于首先创建#temp 表,然后开始事务,以避免事务的 scope 中的任何 DDL stmts。

sp_dboption tempdb, 'ddl in tran',true sp_dboption tempdb, 'ddl in tran',true

the above shuld work,even am also not able to create /update #tables when proc created with anymode.以上应该可以工作,即使在使用任何模式创建 proc 时也无法创建 /update #tables。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM