Reputation: 3854
I have three columns two are of date types and one is of int
The third column stores the difference between two dates in years.
What could be the constraint for this?
The colums are like:
total_years int
from_year datetime
to_year datetime
The total_years is the difference between two dates(in years)
Upvotes: 1
Views: 310
Reputation: 453358
Seems like you need a computed column not a constraint
CREATE TABLE YourTable
(
from_year DATETIME,
to_year DATETIME,
total_years AS DATEDIFF(YEAR, from_year, to_year)
)
Upvotes: 3