【问题标题】:The 'CREATE TABLE' command is not allowed within a multi-statement transaction in the 'tempdb' database“tempdb”数据库中的多语句事务中不允许使用“CREATE TABLE”命令
【发布时间】:2019-08-27 13:06:27
【问题描述】:

我正在使用 Sybase 和 Apache Metamodel 来获取表数据及其信息的 java 项目。现在“ddl in tran”选项是正确的,但是仍然当我使用 Apache Metamodel 获取列详细信息时,它给了我错误:

com.sybase.jdbc4.jdbc.SybSQLException:“tempdb”数据库中的多语句事务中不允许使用“CREATE TABLE”命令。

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

【问题讨论】:

    标签: java sybase-ase15 apache-metamodel


    【解决方案1】:

    临时数据库中的“ddl in tran”选项也需要“开启”。系统管理员或具有 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 
    

    以下是在事务中创建表的示例:

    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> 
    

    【讨论】:

      【解决方案2】:

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

      必须小心使用该选项。

      【讨论】:

        猜你喜欢
        • 2019-01-19
        • 2015-08-28
        • 1970-01-01
        • 2016-04-30
        • 1970-01-01
        • 2014-03-03
        • 1970-01-01
        • 2011-09-27
        • 1970-01-01
        相关资源
        最近更新 更多