I am looking for an elegant way to copy down a value from a parent tuple to a child. I need it to be copied as it can change independently of the parent value, but that is the baseline to start.
Here is a simplified version of the table:
CREATE TABLE Parent (
Id INT NOT NULL PRIMARY KEY,
ParentValue VARCHAR(128)
);
CREATE TABLE Child (
Id INT NOT NULL PRIMARY KEY,
ParentId INT NOT NULL FOREIGN KEY REFERENCES Parent(Id),
ChildValue VARCHAR(128)
);
Now what I am looking to do is this:
UPDATE Child
SET ChildValue = Parent.ParentValue
WHERE TRUE
Does that makes sense? I have a looping way, but it does not seem efficient for the multitude of records I plan on running it for.