Randy B.
Randy B.

Reputation: 453

SQL Server 2008 R2 and Check Constraints

I am using SQL Server 2008 R2 and for my prototype I want to input a bunch of historical data, then I would like to put in a constraint such as

ProductionDate >= GETDATE() 

but I cannot save it after I do this, since the system will not alter the tables after the historical data fails the check.

What do I do?

Thank you

Upvotes: 1

Views: 350

Answers (1)

twoleggedhorse
twoleggedhorse

Reputation: 5048

The point of a constraint is to prevent invalid data. Either remove your historical data and place it in a backup table or update it so that the constraint is honoured; You will have to do the validation on your front end otherwise.

Another alternative is to have an Archive flag and incorporate that into your constraint:

ProductionDate >= GETDATE() OR Archive = 1

Upvotes: 1

Related Questions