db2不能使用小写名称删除外键

时间:2013-06-12 16:20:53

标签: foreign-keys db2

我试图通过命令行删除DB2中的外键。我已经成功了很多次,我确信我使用了正确的语法:

db2 "alter table TABLENAME drop constraint fk_keyname"

输出:

DB21034E  The command was processed as an SQL statement because it was not a 
valid Command Line Processor command.  During SQL processing it returned:
SQL0204N  "FK_KEYNAME" is an undefined name.  SQLSTATE=42704

我的所有外键都是用大写名称创建的。除了我现在要放弃的钥匙。我不知道如何使用小写名称创建,但它似乎不会删除小写的键。

当我尝试添加此外键时(虽然它仍然存在),我收到以下消息:

DB21034E  The command was processed as an SQL statement because it was not a 
valid Command Line Processor command.  During SQL processing it returned:
SQL0601N  The name of the object to be created is identical to the existing 
name "fk_keyname" of type "FOREIGN KEY".  SQLSTATE=42710

有谁知道如何删除具有小写名称的外键?

mustaccio的答案奏效了。试过各种报价,但这种做法就是诀窍:

db2 'alter table TABLENAME drop constraint "fk_keyname"'

1 个答案:

答案 0 :(得分:1)

DB2会将对象名称转换为大写,除非它们被引用。通常,创建具有较低或混合大小写名称的对象并不是一个好主意。如果您的外键实际上是“fk_keyname”(全部小写),请运行db2 "alter table TABLENAME drop constraint \"fk_keyname\""db2 'alter table TABLENAME drop constraint "fk_keyname"'

顺便说一下,这种行为并不是DB2独有的。