Discussion:
Generating FK references in Table script for child table script only
(too old to reply)
Jim Fuller
2010-06-16 19:54:45 UTC
Permalink
When generating a script for a table taht has FK's associated to it we
only want to have the resulting script to include the alter table for
the child table. When I check the Foreign Key Create Outside radio
button it includes teh FK alter table for all FK's whether child or
parent roles. Is there a way to restrict this to child only FK
constraints? We're using DB2 9.5 and PowerDesigner 15.1.
Mark Brady
2010-06-17 18:12:20 UTC
Permalink
Not a DB2 guy. I'm an Oracle guy but I think in SQL Server too, they
only have FK constraints on the child. The parent has a PK, and the
DBMS tracks which FKs rely on which PKs in order to watch for parent
id changes.

DB2 also add an FK constraint to the parent? FK?
Mark Brady
2010-06-17 18:33:23 UTC
Permalink
Post by Mark Brady
Not a DB2 guy. I'm an Oracle guy but I think in SQL Server too, they
only have FK constraints on the child. The parent has a PK, and the
DBMS tracks which FKs rely on which PKs in order to watch for parent
id changes.
DB2 also add an FK constraint to the parent? FK?
Yeh I just read the documentation. There's no parent FK. Like every
other DB there's a parent PK. Make sure that you've told it to make
PK's inline.

I just built a quickly little PDM to test it and this was with the
defaults. The PK is inline and FK is not.


--==============================================================
-- Table: TABLE_1
--==============================================================
create table TABLE_1
(
COLUMN_1 BIGINT not null,
COLUMN_2 CHAR,
constraint P_KEY_1 primary key (COLUMN_1)
);

--==============================================================
-- Table: TABLE_2
--==============================================================
create table TABLE_2
(
COLUMN_1 BIGINT,
COLUMN_3 CHAR,
COLUMN_4 DATE
);

alter table TABLE_2
add constraint F_REFERENCE_1 foreign key (COLUMN_1)
references TABLE_1 (COLUMN_1)
on delete restrict on

Loading...