foreign key relation between tables



IBM's flagship relational database management system

foreign key relation between tables

Postby Kal El » Mon Jun 21, 2010 1:08 pm

Hello,

I have two tables having 1 to 0 , 1 to many relationship.

also the structure is as follows:

Table1
--------
contract no. (PK) smallint,
account no. smallint,
contract creation date timestamp

Table2
--------
contract id (PK) smallint,
contract no. (FK) smallint

how to insert /delete data into these tables should i first enter data into child table and then parent table or vice versa.

Does the condition remain the same during deletion as well?

Kindly help me out.I have always had this confusion between tables having parent child relation
Kal El
 
Posts: 9
Joined: Mon Jun 21, 2010 1:05 pm
Has thanked: 0 time
Been thanked: 0 time

Re: foreign key relation between tables

Postby manasi » Mon Jun 21, 2010 1:23 pm

Hi ,

As per my knowledge you need to first insert the data in parent table and then corrsopnding data in child table.
The FK of child table should have matching PK in parent table.
While Deletion of data you need to check the delete rules for referential integrity constraint.
It can be either On Delete Cascade,On Delete Set NULL,On Delete Restrict.

Regards,
Manasi.
manasi
 
Posts: 3
Joined: Fri May 21, 2010 10:44 am
Has thanked: 0 time
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post