Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Database (http://www.go4expert.com/forums/database-forum/)
-   -   why we should introduce the referential integrity before the data entered? (http://www.go4expert.com/forums/introduce-referential-integrity-data-t342/)

go4expert 1Jun2005 14:11

why we should introduce the referential integrity before the data entered?
 
why we should introduce the referential integrity before the data entered?

shabbir 1Jun2005 14:12

Re: why we should introduce the referential integrity before the data entered?
 
The one and the only reason that we should introduce the referential integrity before the data entered so that the whatever data has been entered also follows the same referential integrity.

If we take an example it will be much clearer

Employee
--------
EmpId
Name
Address
DeptId

Department
----------
DeptId
DeptName

Case 1:
------
Now there is no referential integrity initially and there is no data as well.

Say now I would like to insert a new employee. Then as there is no data in the department table the employee can only be in on department but if we dont have the referential integrity a situation may come where there is no valid department for the employee.

Case 2:
------
Now there are some Departments and some employees. Then when I mistype a department then again the employee goes into a no department situation.

If we dont have the tables as empty and would like to put the referential integrity on the existing data there can be situation where they will not follow the referential integrity and so Habraken, suggest that one should probably set up relationships and enforce referential integrity before one tries to enter any data in the related tables.


All times are GMT +5.5. The time now is 05:07.