我正在尝试将数据库的逻辑模型转换为DDL脚本,但是我不知道如何在DDL脚本或Data Modeller中修复此错误:-错误:FK名称长度超过了允许的最大长度(30) 它似乎是基于我的联结表的主键,它是由两个相邻表中的两个外键组成的。
我曾尝试更改相邻表中主键的名称,但是当我尝试使用Data Modeler生成新的DDL脚本时,它仍然会生成旧脚本。
下面是创建3个表并将它们链接在一起的代码部分:
CREATE TABLE items (
item_no NUMBER (8) NOT NULL,
"year" DATE,
price NUMBER (20,2)
);
ALTER TABLE items ADD CONSTRAINT items_pk PRIMARY KEY ( item_no );
CREATE TABLE purchase_order (
order_no NUMBER(8) NOT NULL,
quantity INTEGER,
item_description VARCHAR2(200),
unit_price NUMBER(20,2),
total NUMBER(20,2),
order_date DATE,
sales_person_code VARCHAR2(5) NOT NULL,
supplier_id NUMBER(3) NOT NULL
);
ALTER TABLE purchase_order ADD CONSTRAINT purchase_order_pk PRIMARY KEY ( order_no );
CREATE TABLE purchase_order_items (
purchase_order_order_no NUMBER(8) NOT NULL,
items_item_no NUMBER(8) NOT NULL
);
ALTER TABLE purchase_order_items ADD CONSTRAINT purchase_order_items_pk PRIMARY KEY ( items_item_no,
purchase_order_order_no );
ALTER TABLE purchase_order_items
ADD CONSTRAINT purchase_order_items_items_fk FOREIGN KEY ( items_item_no )
REFERENCES items ( item_no );
-- ERROR: FK name length exceeds maximum allowed length(30)
ALTER TABLE purchase_order_items
ADD CONSTRAINT purchase_order_items_purchase_order_fk FOREIGN KEY ( purchase_order_order_no )
REFERENCES purchase_order ( order_no );
ALTER TABLE purchase_order
ADD CONSTRAINT purchase_order_sales_person_fk FOREIGN KEY ( sales_person_code )
REFERENCES sales_person ( code );
ALTER TABLE purchase_order
ADD CONSTRAINT purchase_order_supplier_fk FOREIGN KEY ( supplier_id )
REFERENCES supplier ( id );
所以我不确定FK名称长度是否太长以及我需要在脚本中更改哪些内容以解决此错误。
答案 0 :(得分:0)
Oracle将标识符限制为30个字符,因此
purchase_order_items_purchase_order_fk
需要短路。也许像poi_purchase_porder_fk
之类的东西。