2010-11-09 67 views
1

我已經繼承了啓用了'unique auto_identity index'選項的Sybase數據庫。作爲升級過程的一部分,我需要一些額外的列在這個數據庫添加到表即將列添加到具有唯一auto_identity索引選項的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使用到訪問數據庫,並且它只會啓用「唯一auto_identity索引」選項而影響表格。

要解決該問題,請使用不同的SQL客戶端(例如,通過JDBC)連接到數據庫,或在命令行上使用isql

回答

1

對於具有這種列的ALTER TABLE應該沒有問題;錯誤信息表明問題涉及其他事情。我需要看到CREATE TABLE DDL。

即使我們不能ALTER TABLE,我們將首先嚐試,但有幾種解決方法。

迴應

哈!內部Sybase錯誤。打開TechSupport案例。

解決方法:

  1. 確保你得到J此時確切的DDL。 sp_help。請注意IDENTITY列和索引。
  2. 創建一個臨時表,完全一樣。使用(1)中的DDL。排除索引。
  3. INSERT new_table SELECT old_table。如果表格很大,則將其分成每批1000行。
  4. 現在創建索引。

如果表是非常大的,而時間是一個問題,然後使用BCP。首先需要進行研究,之後我很樂意回答問題。

+0

我更新了原始的一些示例代碼,產生了錯誤。 – tja 2010-11-11 15:51:32

+0

@tja:迴應 – PerformanceDBA 2010-11-12 22:44:51

+0

是一個錯誤,請參閱更新2。 – tja 2010-11-23 17:18:54

0

當我運行示例代碼我第一次得到的錯誤:

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

這是毫無疑問的,因爲你的表中的數據複製需求,因爲新列不爲空。這將使用我認爲的tempdb,並且您發佈的錯誤消息引用臨時表。是否有可能爲tempdb意外啓用了此dboption?

這是在黑暗中的一點點,因爲我只有12.5在這裏測試,它對我有用。或者它可能是一個錯誤。

相關問題