1

我试图通过命令行在 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"'
4

1 回答 1

1

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

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

于 2013-06-12T17:21:20.403 回答