View previous topic :: View next topic
|
Author |
Message |
vikas kumar jain
New User
Joined: 02 Aug 2006 Posts: 9 Location: noida
|
|
|
|
I want to know whether to set the referential integrity b/w Parent and child tables of DB2, is it must that we need the referential table( Child table) empty(with no data)? |
|
Back to top |
|
|
wanderer
Active User
Joined: 05 Feb 2007 Posts: 199 Location: Sri Lanka
|
|
|
|
I don't remember it exactly right now, but no, it need not be empty. Although the table will go to CHECK PENDING status and you will have to run a CHECK DATA utility. |
|
Back to top |
|
|
vikas kumar jain
New User
Joined: 02 Aug 2006 Posts: 9 Location: noida
|
|
|
|
Thanks a lot....
Cud u tell that what is basically CHECK DATA utility and what it does in brief? |
|
Back to top |
|
|
wanderer
Active User
Joined: 05 Feb 2007 Posts: 199 Location: Sri Lanka
|
|
|
|
It checks the table data for violation of constraints. Foreign key is one of the constraints. If there are no violations then CHECK PENDING status is removed.
This is DB2's way of cautioning the user about integrity of data.
Please see the 'Utility Gude' listed under link "Manual" on top of this page for more details. Hope it helps. |
|
Back to top |
|
|
prasadvrk
Active User
Joined: 31 May 2006 Posts: 200 Location: Netherlands
|
|
|
|
A foreign key could be null, but if present should be the primary key in the parent table.
eg. An employee need not be associated with a department in EMP table but if an employee has department say 01 then there should be a row with 01 as department number in DEPT table |
|
Back to top |
|
|
sagard
New User
Joined: 16 May 2007 Posts: 4 Location: Pune
|
|
|
|
I am not sure i understand your last quote,
'A foreign key could be null, but if present should be the primary key in the parent table.'
for what i understand is that foreign key for one table is primary key for some other table & primary key cannot be null. |
|
Back to top |
|
|
tosaurabh20
New User
Joined: 08 Jun 2007 Posts: 26 Location: Noida
|
|
|
|
prasadvrk wrote: |
A foreign key could be null, but if present should be the primary key in the parent table.
eg. An employee need not be associated with a department in EMP table but if an employee has department say 01 then there should be a row with 01 as department number in DEPT table |
Hi Vikas/Sagar
This statement of Prasad is very much correct however i will make it more elaborative to make the picture very clear.
Suppose there are two tables in database named A and B. Primary key of A is foreign key of B. Now suppose if you are inserting a row in B and it is not mandatory that you need to keep a value for the foreign key column in B. It can be null. In that scenario for this row of B there wont be any relation with A. But if you are inserting the values for foreign key column in B then it is mandatory that the same value should there in primary key column of A.
Hope this clear your doubt.
Correct me if i am worng somewhere.
Thanks
Saurabh |
|
Back to top |
|
|
vini_srcna
Active User
Joined: 26 May 2005 Posts: 178 Location: Copenhagen, Denmark
|
|
|
|
That makes more sense provided the foreign key is defined as nullable field. So i would say it is not a standard solution and you need to have a look at the catalog before deciding it. |
|
Back to top |
|
|
|