Results 1 to 5 of 5

Thread: time constraint

  1. #1
    Join Date
    Mar 2012
    Posts
    1

    Unanswered: time constraint

    how do we do this?

    startTime time not null,
    endTime time (check endTime > startTime), -- if end time is not null
    startDate date not null,
    endDate date (check endDate > startDate), --if end date is not null

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Code:
    CREATE TABLE foo
    (
       startTime   time not null,
       endTime     time check (endTime is null or endTime > startTime),
       startDate   date not null,
       endDate     date check (endDate is null or endDate > startDate)
    );

  3. #3
    Join Date
    May 2008
    Posts
    277
    The IS NULL check isn't required. The constraint will only fail if it evaluates to FALSE, and NULL > some date will evaluate to NULL.

  4. #4
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Quote Originally Posted by futurity View Post
    The IS NULL check isn't required. The constraint will only fail if it evaluates to FALSE, and NULL > some date will evaluate to NULL.
    True, but I think for documentation and clarity purposes it's still a good idea to have it.

  5. #5
    Join Date
    May 2008
    Posts
    277
    True, this too. Perhaps I should've said, it's not strictly required.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •