在 'tempdb' 数据库的多语句事务中不允许 'CREATE TABLE' 命令

The 'CREATE TABLE' command is not allowed within a multi-statement transaction in the 'tempdb' database

我正在从事 java 项目,我在其中使用 Sybase 和 Apache Metamodel 来获取 table 数据及其 information.Now ” ddl in tran" 选项是正确的,但是当我使用 Apache Metamodel 获取列详细信息时仍然给我错误:

com.sybase.jdbc4.jdbc.SybSQLException: The 'CREATE TABLE' command is not allowed within a multi-statement transaction in the 'tempdb' database.

我在 Windows 10 上安装了 Sybase ASE 15.5。

临时数据库中的 "ddl in tran" 选项也需要 "on"。系统管理员或 sa_role 的人可以这样做:

1> use master
2> go
1> sp_dboption tempdb, 'ddl in tran', 'true'
2> go
Warning: Attempting to change database options for a temporary database. Database options must be kept consistent across all temporary databases.
Database option 'ddl in tran' turned ON for database 'tempdb'.
Running CHECKPOINT on database 'tempdb' for option 'ddl in tran' to take effect.
(return status = 0)

如警告所示,如果您有多个临时数据库,这需要在所有临时数据库中保持一致。命令完成后,可以使用 sp_helpdb:

检查选项
1> sp_helpdb
2> go

[stuff deleted]

 tempdb                            104.0 MB              sa             2      Aug 05, 2019             no_recovery                     0               NULL        
 select into/bulkcopy/pllsort, trunc log on chkpt, ddl in tran, mixed log and data, allow wide dol rows 

这是在交易中创建 table 的示例:

1> use tempdb
2> go
1> begin tran
2> go
1> create table foo ( k int not null, value varchar(25) null) 
2> go
1> commit
2> go
1> 

这个可以使用(sp_dboption tempdb, 'ddl in tran', 'true')但是把这个设置为true不是一个好习惯,它可能会导致tempdb的并发问题。

必须小心使用该选项。