Page 1 of 1

foreign key relation between tables

PostPosted: Mon Jun 21, 2010 1:08 pm
by Kal El
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

Re: foreign key relation between tables

PostPosted: Mon Jun 21, 2010 1:23 pm
by manasi
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.