Link to home
Start Free TrialLog in
Avatar of 25112
25112

asked on

constraint to allow past data but enforce new rule from now on?

there is a column in which the data allowed previously was 6 characters. . Now with the new logic, they are expanded to allow 8 characters only. Is there a constraint that can be designed in SQL Server that will CHECK to make sure all new entries from now on will allow and strictly expect 8 characters, but will allow the existing 6 records as is without complaining, but will not allow any new entries with 6 characters?
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

ALTER TABLE [dbo].[YOUR_TABLE]
ADD CONSTRAINT [LengthConstraint] CHECK (DATALENGTH([your_column]) = 8 ) WITH NOCHECK
Avatar of 25112
25112

ASKER

ged325,
if it is a NOCHECK, then even a 9 character or 7 can get in unsuspected, right?

we only want the old records that are 6 in length.. and anything new should be 8 in length (no NULLs)
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 25112

ASKER

i got it now.. thanks ged325!