-2

enter image description here

Student can select any number of CourseBatchCode,

in Case 3 CourseBatchCode is selected This is my Table I want to put validation on the table that

1)ENDTIME should not be between following Start time and end time

2)EndTime should be less than following Start Time and End time

Tanner
  • 22,205
  • 9
  • 65
  • 83
Akki
  • 61
  • 1
  • 2
  • 10

1 Answers1

1

If you want to check that EndTime is after StartTime for a given row then you can use a check constraint like so;

ALTER TABLE [YourTableName] 
ADD CONSTRAINT [startBeforeEnd]
CHECK (
    [EndTime] > [StartTime]
)

If you want the check constraint to work across rows you would have to use a Trigger, or maybe create a UDF (User Defined Function) and use this in the Constraint - however these are usually discouraged because it is easy to cause logic and performance problems with them.

The recommended approach in these cases is to do this type of validation on the client (application) side and not worry about it in the database...

Milney
  • 6,253
  • 2
  • 19
  • 33