Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Database Programming

How do I maintain referential integrity when updating lookup tables by hilfy
Posted: 20 Jan 04

Situation:  You have a table (lookup table) with two (possibly more) fields Code, Description.  The Code field is used in one or more other tables (master table(s)) to point to the description.

Problem: You want to change one of the Code fields, but it is already being used in one or more master tables.

Solution 1: If there are no referential integrity constraints in the database, you can just update the Code field and update the value for that field in the master tables.

Solution 2: If there are referential integrity constraints, you have to go through a little more complicated process (steps MUST be done in this order.)

1. Add a new record to the lookup table with the new code and the old description.
2. Update all of the records in the Master table(s) to have the new code.  A simple sql template for this is:
  update MasterTable
  set CodeField = NewValue
  where CodeField = OldValue

3. Delete the record with the old code from the lookup table.

Back to Embarcadero: Delphi FAQ Index
Back to Embarcadero: Delphi Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close