Create table with constraint based on another column Say a database has the following tables:


movie(id, title, rent_period)
customer(id, name)


I would like to create the following table:

CREATE TABLE rental (
   movie_id int,
   customer_id int,
   rent_date date,
   return_date date,
   FOREIGN KEY (movie_id) REFERENCES movie(id),
   FOREIGN KEY (customer_id) REFERENCES customer(id)
   PRIMARY KEY rental_pk (movie_id, customer_id)
)     


Can I make make the return_date field be populated automatically as rental(rent_date) + movie(rent_period)?
I would do this using a trigger on your rental table. Trigger before insert - set the return_date column value to be the rent_date value in the data being saved, plus look up the value of movie.rent_period based on the movie_id value being saved.