You are on page 1of 4

http://www-1.ibm.com/support/docview.wss?

uid=swg21124718

How to create a foreign key and


difference between Identifying
and Non-Identifying relations?
Technote (FAQ)
Problem
How to create a foreign key and difference between Identifying and
Non-Identifying relations?
Solution
QUESTION:
How to create a foreign key and difference between Identifying and
Non-Identifying relations?
ANSWER:
Steps to create a foreign key relationship in Rose
1. Create a Schema
a. Right click on the Logical View and select Data Modeler
b. Then select New / Schema
2. Create a Table
a. Right click on the Schema
b. Select Data Modeler / New / Table
c. Right click on the table and name the table A
3. Create a Primary Key for table A
a. Right click on the table and select Open Specifications
b. Click on the Columns Tab
c. Right click in the white area and select insert
d. Right click on the name (Col_1) and select Open Specifications
e. If you would like the change the name you will do so on the
general tab
f. To make this a Primary key you want to go to the types tab and

click Primary Key and also Unique Constraint


Note: You can also do this on the col tab, 2000e\2001 PK checkbox,
2001a click below PK column header, select PK from drop down
listbox
g. Now click Apply and OK
h. So your primary key is created
4. Create a new table
a. Right click on the Schema
b. Select Data Modeler / New / Table
c. Right click on the table and name the table B
5. Create a Data Model Diagram
a. Right click on Schema and select Data Modeler / New / Data
Model Diagram
6. Place the tables on the data model diagram
7. Create the foreign Key
a. Click on the Identifying relationship
b. Then go to table A and draw the relationship from Table A to
Table B
c. This will create a FPK (Foreign Primary Key relationship between
Table A and B.
So you need to make sure that your primary key is defined in the
table and it will then place the key (Col_A) in Table B. You do not
need to create Col_A in table B it will automatically get created.
There are two kinds of relationships that create FKs, Identifying and
Non-Identifying.
Per on line help:
------------------------------------------------------------------RELATIONSHIPS - DM
In Data Modeler, a data model relationship models as an object
model association that relates to a class with the stereotype
<<table>>.
Identifying relationships represent composite aggregations,
An Identifying relationship specifies that a child object cannot

exist without the parent object. To enforce the rule, the foreign
key in the child object also becomes part of that objects primary
key, thus creating a composite aggregation.
Non-identifying relationships represent associations,
A Non-identifying relationship specifies a regular association
between objects. It uses a 1:1 or 1:n cardinality. Non-identifying
relationships can be specified as optional where a parent is not
required or mandatory where a parent is required by setting the
parent table cardinality. To specify a relationship as optional
set the parent cardinality to 0..1. To specify a relationship as
mandatory set the parent cardinality to 1.
------------------------------------------------------------------Consider the following example,
Two tables Parent and Child.
Each contains one column; Parent_ID & Child_ID,
which are their respective primary keys.
Notice that with Identifying relation, the primary
key in the child is a concatination of the two
primary keys:
//** Non-Identifying
CREATE TABLE Parent (
Parent_ID NUMBER ( 5 ) NOT NULL,
CONSTRAINT PK_Parent2 PRIMARY KEY (Parent_ID)
);
CREATE TABLE Child (
Parent_ID NUMBER ( 5 ) NOT NULL,
Child_ID NUMBER ( 5 ) NOT NULL,
CONSTRAINT PK_Child3 PRIMARY KEY (Child_ID)
);
ALTER TABLE Child ADD ( CONSTRAINT FK_T_14 FOREIGN
KEY (Parent_ID)
REFERENCES Parent (Parent_ID));
//** Identifying
CREATE TABLE Parent (
Parent_ID NUMBER ( 5 ) NOT NULL,
CONSTRAINT PK_Parent2 PRIMARY KEY (Parent_ID)

);
CREATE TABLE Child (
Child_ID NUMBER ( 5 ) NOT NULL,
Parent_ID NUMBER ( 5 ) NOT NULL,
CONSTRAINT PK_Child3 PRIMARY KEY (Parent_ID, Child_ID)
);
ALTER TABLE Child ADD ( CONSTRAINT FK_Child5
FOREIGN KEY (Parent_ID)
REFERENCES Parent (Parent_ID));

You might also like