使用唯一的 auto_identity 索引选项向 sybase 表添加列
我继承了一个启用了“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于这样的列 ALTER TABLE 应该没有问题;错误消息表明问题与其他问题有关。我需要查看 CREATE TABLE DDL。
即使我们不能更改表(我们将首先尝试),也有几种解决方法。
回应
哈! Sybase 内部错误。打开技术支持案例。
解决方法:
如果表非常大,并且时间是一个问题,则使用 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:
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.
当我运行您的示例代码时,我首先收到错误:
这毫无疑问是因为表中的数据需要复制出来,因为新列不为空。我认为这将使用 tempdb,并且您发布的错误消息引用了临时表。是否有可能意外为 tempdb 启用了此 dboption?
这有点盲目,因为我这里只有 12.5 来测试,但它对我有用。或者这可能是一个错误。
When I ran your sample code I first get the error:
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.