sql - Adding constraint to a table referencing a subset of records of another table -


say have following tables:

user(user_id, name, age,...) job(job_id, salary, user_id) 

i want have constraint on job whenever job's salary > 20,000, user doing job must of age >= 18. have tried check constraint seems work on single table only?

you can user-defined function. function can value in other table.

i'm not recommending approach. many applications, wrap insert/update statements in stored procedure/function , put logic there. however, possible without trigger.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -