0

I have a problem with my code. As you can see i Try to have a sort of CHECK constraint using two columns in the same table but seems does not work. My need is to accept value in EffectiveEndDate only if they are > that EffectiveStartDate.

Any idea how to solve it? thanks for your support! :-)

CREATE TABLE dbo.Test 
(   
EffectiveStartDate  dateTime2(2)        NOT NULL,
EffectiveEndDate    dateTime2(2)        NOT NULL
    CONSTRAINT CK_CmsSponsoredContents_EffectiveEndDate CHECK (EffectiveEndDate > EffectiveStartDate),
);
GibboK
  • 71,848
  • 143
  • 435
  • 658

1 Answers1

4

You've got a comma in the wrong spot:

CREATE TABLE dbo.Test(  
  EffectiveStartDate dateTime2(2) NOT NULL,
  EffectiveEndDate   dateTime2(2) NOT NULL,  -- added missing comma
  CONSTRAINT CK_CmsSponsoredContents_EffectiveEndDate CHECK (EffectiveEndDate>EffectiveStartDate)
)

Removed a comma at the end of the check constraint declaration.

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502