简体   繁体   中英

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.

You can let the datamodeler generate the relational model and the DDL code. 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.

(example) ERD

ERD

Relational model (generated)

关系模型

DDL code (generated)

DDL 代码

APEX script editor (notice the CHECK constraint enforcing the "arc")

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

-- 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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