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.
ASCII a stupid question, get a stupid ANSI
24 hours in a day .... 24 beer in a case .... coincidence?
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.
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
Click Here to Expand Forum to Full Width