使用唯一的auto_identity索引选项将列添加到sybase表中 [英] Adding columns to a sybase table with unique auto_identity index option

查看:257
本文介绍了使用唯一的auto_identity索引选项将列添加到sybase表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个启用了唯一自动识别索引选项的Sybase数据库。作为升级过程的一部分,我需要在此数据库的表中添加一些额外的列,即

I've inherited a Sybase database that has the 'unique auto_identity index' option enabled on it. As part of an upgrade process I need to add a few extra columns to the tables in this database i.e.

alter table mytable add <newcol> float default -1 not null

当我尝试执行此操作时,出现以下错误:

When I try to do this I get the follow error:

Column names in each table must be unique, column name SYB_IDENTITY_COL in table #syb__altab....... is specifed more than once

是否可以在启用此属性的情况下向表中添加列?

Is it possible to add columns to a table with this property enabled?

更新1:

我创建了以下测试来复制问题:

I created the following test that replicates the problem:

use master
sp_dboption 'esmdb', 'unique auto_identity indexoption',true

use esmdb

create table test_unique_ids (test_col char)

alter table test_unique_ids add new_col float default -1 not null

此处的alter table命令产生错误。 (已在ASE 15 / Solaris和15.5 / Windows上尝试过此操作)

The alter table command here produces the error. (Have tried this on ASE 15/Solaris and 15.5/Windows)

更新2:

这是Sybase dbisql 界面中的错误,Sybase Central和Interactive SQL的客户端工具使用该错误来访问数据库,并且该错误似乎只影响带有'unique auto_identity index'选项的表。

This is a bug in the Sybase dbisql interface, which the client tools Sybase Central and Interactive SQL use to access the database and it only appears to affect tables with the 'unique auto_identity index' option enabled.

要解决此问题,请使用其他SQL客户端(例如,通过JDBC)连接到数据库,或在服务器上使用 isql

To work around the problem use a different SQL client (via JDBC for example) to connect to the database or use isql on the command line.

推荐答案

使用这样的列对ALTER TABLE应该没有问题;错误消息表示问题与其他有关。我需要查看CREATE TABLE DDL。

Should be no problem to ALTER TABLE with such columns; the err msg indicates the problem regards something else. I need to see the CREATE TABLE DDL.

即使我们不能更改表(我们将首先尝试),也有几种解决方法。

Even if we can't ALTER TABLE, which we will try first, there are several work-arounds.

回复

哈! Sybase内部错误。打开技术支持案例。

Hah! Internal Sybase error. Open a TechSupport case.

解决方法:


  1. 确保您获得了确切的DDL。 sp_help。请注意IDENTITY列和索引。

  2. 创建一个临时表,完全相同。使用(1)中的DDL。

  3. 插入new_table SELECT old_table。如果表很大,则将其分成每批1000行的批处理。

  4. 现在创建索引。

  1. Make sure you get jthe the exact DDL. sp_help . Note the IDENTITY columns and indices.
  2. Create a staging table, exactly the same. Use the DDL from (1). Exclude the Indices.
  3. INSERT new_table SELECT old_table. If the table is large, break it into batches of 1000 rows per batch.
  4. Now create the Indices.






如果表很大,并且AND时间成为问题,则使用bcp。您需要先进行研究,然后我很乐意回答问题。


If the table is very large, AND time is an issue, then use bcp. You need to research that first, I am happy to answer questions afterwards.

这篇关于使用唯一的auto_identity索引选项将列添加到sybase表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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