Reputation: 479
I need to add a Check constraint to a Column named Departure. This column has the smalldatetime data type.
The Check Constraint should state that: The date and time entered in the Departure column must be at least 6 hours from whatever the current time is when the date is being entered.
Can anyone help with the code.
Thank you
Upvotes: 1
Views: 169
Reputation: 5900
This should do it:
ALTER TABLE [YourTableName]
ADD CONSTRAINT DepartureLaterThan6Hours CHECK ([Departure] > dateadd(HOUR, 6, GetDate()));
Upvotes: 2