使用唯一的 auto_identity 索引选项向 sybase 表添加列

发布于 2024-10-01 20:46:18 字数 997 浏览 1 评论 0原文

我继承了一个启用了“unique auto_identity index”选项的 Sybase 数据库。作为升级过程的一部分,我需要向该数据库中的表添加一些额外的列,即

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

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

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

是否可以向启用此属性的表添加列?

更新 1:

我创建了以下测试来重现该问题:

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 上尝试过此操作)

更新 2:

这是 Sybase dbisql 界面中的一个错误,客户端使用 Sybase Central 和 Interactive SQL 使用该界面用于访问数据库,它似乎只影响启用了“unique auto_identity index”选项的表。

要解决此问题,请使用不同的 SQL 客户端(例如通过 JDBC)连接到数据库或在命令行上使用 isql

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?

Update 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

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

Update 2:

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扎心 2024-10-08 20:46:18

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

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

回应

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

解决方法:

  1. 确保您获得准确的 DDL。 sp_help 。请注意 IDENTITY 列和索引。
  2. 创建一个临时表,完全一样。使用 (1) 中的 DDL。排除指数。
  3. INSERT 新表 SELECT 旧表。如果表很大,请将其分成批次,每批次 1000 行。
  4. 现在创建索引。

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

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.

Responses

Hah! Internal Sybase error. Open a TechSupport case.

Workaround:

  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.

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.

桃扇骨 2024-10-08 20:46:18

当我运行您的示例代码时,我首先收到错误:

数据库“mydb”未启用“选择进入”数据库选项。无法完成带有数据复制的 ALTER TABLE。设置“选择进入”数据库选项并重新运行

这毫无疑问是因为表中的数据需要复制出来,因为新列不为空。我认为这将使用 tempdb,并且您发布的错误消息引用了临时表。是否有可能意外为 tempdb 启用了此 dboption?

这有点盲目,因为我这里只有 12.5 来测试,但它对我有用。或者这可能是一个错误。

When I ran your sample code I first get the error:

The 'select into' database option is not enabled for database 'mydb'. ALTER TABLE with data copy cannot be done. Set the 'select into' database option and re-run

This is no doubt because the data within your table needs copying out because the new column is not null. This will use tempdb I think, and the error message you've posted refers to a temp table. Is it possible that this dboption has been accidentally enabled for the tempdb?

It's a bit of a shot in the dark, as I only have 12.5 to test on here, and it works for me. Or it could be a bug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文