Can I define a default value for a column based on a column value in another table? eg. alter table product modify location_id (default select location_id from user_listing where product.user_id = user_listing.user_id). Thanks for the help.
03-21-2001, 06:52 PM
NO, you can't.
03-22-2001, 01:14 PM
You *might* be able to do that with a "before insert" trigger. The problem I used to always run into with triggers was the "mutating table" error, but I could usually work around it.
03-22-2001, 01:35 PM
macswell is right, you can do it if you use the before insert trigger. Just remember that you cannot do a select on the table that the trigger is on or even selects on that table in a roundabout way (does an insert on another table that selects from the original).
To get the default value, the query would be like:
:new.user_id = user_listing.user_id