MySQL Columns default value is the default value from primary key of another table
(Table)File has many (Table)Words
FK Words.file_id related to a single File.id
Default value of Words.frame is equal to File.frame for that PK/FK
Does this type of default relationship have a name? Examples on getting this setup? (MySQL)
Edit
The reason for this is that words may have the same frame as the file and if they do, we wa开发者_如何转开发nt to use that default, however some may not and need to be set manually. Is this really bad practice to handle it this way as described in one of the answers? Any improvement suggestions?
You may want to use a Trigger. You should be able to mimick the "default value" of Words.frame
to be based on the value of another field from the File
table.
It doesn't have a name, but feels like denormalization / data duplication to me.
@Daniel Vassallo suggests an insert trigger for this, and I think that would be the best approach as well if this is really what you need.
精彩评论