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

Discussion in 'Database' started by go4expert, Jun 1, 2005.

  1. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    9
    Trophy Points:
    0
    why we should introduce the referential integrity before the data entered?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice