Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我面临一个问题。我已经在 DB2 中创建了一个表。
CREATE TABLE "DDL12" ( "D4_1" decimal(10,0), "D4_2" decimal(10,0), );
我正在尝试在此表上创建一个 PK:-
ALTER TABLE "DDL12" ADD CONSTRAINT "Key4" PRIMARY KEY ("D4_1");
但是在运行命令时,我收到错误说 D4_1 是 NULLABLE。
现在,我怎样才能在这张桌子上创建一个 PK?
谢谢
是的,这是因为您的数据库现在“可能”在该非 PK 列中具有 NULL 值的行。
因此,首先将列设置为 NOT NULL(+ 确保在所有行中具有唯一值),然后使用上面的命令设置主键。
您可以像这样将列更改为非 NULL:
ALTER TABLE "DDL12" MODIFY "D4_1" decimal(10,0) NOT NULL;