简体   繁体   English

如何在 Oracle APEX 中的 Oracle 数据库建模器中重新创建弧关系?

[英]How do you recreate the arc relationship in the Oracle Database Modeler in Oracle APEX?

I'm not sure how to write out a foreign key constraint in Oracle APEX that will represent an arc relationship in the Oracle Database Modeler.我不确定如何在 Oracle APEX 中写出一个外键约束,它将代表 Oracle 数据库建模器中的弧关系。

You can let the datamodeler generate the relational model and the DDL code.您可以让数据建模器生成关系 model 和 DDL 代码。 Then, open the SQL script editor in APEX, paste in the DDL code, give the script a name, and execute it - see screen shots below.然后,在 APEX 中打开 SQL 脚本编辑器,粘贴 DDL 代码,为脚本命名,然后执行它 - 参见下面的屏幕截图。

(example) ERD (示例)ERD

ERD

Relational model (generated)关系型 model(生成)

关系模型

DDL code (generated) DDL 代码(生成)

DDL 代码

APEX script editor (notice the CHECK constraint enforcing the "arc") APEX 脚本编辑器(注意强制执行“弧”的 CHECK 约束)

APEX 脚本编辑器

Script executed执行的脚本

在此处输入图像描述

You may have to tweak the script a bit (if there are error messages).您可能需要稍微调整一下脚本(如果有错误消息)。

Then, you should do some testing, so that you see that the "arc" actually works eg然后,您应该进行一些测试,以便您看到“弧”确实有效,例如

Testing测试

-- these 3 INSERTs must fail
-- {1} event without a "venue id"
insert into event ( 
  id, eventdate, private_home_id, public_space_id 
) values (
  1, sysdate, null, null
) ;
-- ORA-02290: check constraint (...ARC_1) violated

-- {2} private home does not exist
insert into event ( 
  id, eventdate, private_home_id, public_space_id 
) values (
  1, sysdate, 1000, null
) ;
-- ORA-02291: integrity constraint (...EVENT_PRIVATE_HOME_FK) violated - parent
key not found

-- {3} public space does not exist
insert into event ( 
  id, eventdate, private_home_id, public_space_id 
) values (
  1, sysdate, null, 2000
) ;
-- ORA-02291: integrity constraint (...EVENT_PUBLIC_SPACE_FK) violated - parent
key not found

INSERT some data into the PRIVATE_HOME and PUBLIC_SPACE tables在 PRIVATE_HOME 和 PUBLIC_SPACE 表中插入一些数据

-- add a PRIVATE_HOME and a PUBLIC_SPACE
insert into private_home( id, vname ) values ( 1000, 'The Manor' ) ;
insert into public_space( id, vname ) values ( 2000, 'Royal Albert Hall' ) ;


-- add 2 events
insert into event ( 
  id, eventdate, private_home_id, public_space_id 
) values (
  1, sysdate, 1000, null
) ;

insert into event ( 
  id, eventdate, private_home_id, public_space_id 
) values (
  2, sysdate, null, 2000
) ;

select * from event ;
SQL> select * from event ;

        ID EVENTDATE PRIVATE_HOME_ID PUBLIC_SPACE_ID
---------- --------- --------------- ---------------
         1 06-MAY-20            1000                
         2 06-MAY-20                            2000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM