Menu

Add child foreign key on existing record

0 votes

Is there any way to "add" a record as a child to a parent table, when the child record already exists?

"Parents" table:
ParentID (Primary Key)

"Children" table:
ChildID (Primary Key)
ParentID (Foreign Key to Parents.ParentID. Nullable.)

Children table gets populated first by some other process. Some records need to be linked to a ParentID.

Workarounds:

  1. Create another table with a 1:1 relationship to the existing Children
    table, and move ParentID foreign key column to this new table.
    or...
  2. Maximize Children table, update desired record's ParentID, go
    back to Parents table.

Just want to be sure I'm not missing some other way of doing this directly from the Parents screen, without the added complexity of another table.

in How To by (1.9k points)

1 Answer

0 votes
 
Best answer

Knowing nothing more I would say Option #2. Max Child table and update the ParentID (lookup) is the most logical. You could even use MassUpdate to assign multiple child rows.

You could also use a stored procedure to create and automatically assigning a new parent directly from a child.

by (60.2k points)
selected by
Welcome to the dbFront Q&A site, where you can ask questions and receive answers from other members of the community.
 | Minimalist Answer Theme by Digitizor Media
 |
Powered by Question2Answer
...