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?
LVL 5
25112Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
ALTER TABLE [dbo].[YOUR_TABLE]
ADD CONSTRAINT [LengthConstraint] CHECK (DATALENGTH([your_column]) = 8 ) WITH NOCHECK
0
25112Author Commented:
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)
0
Kyle AbrahamsSenior .Net DeveloperCommented:
NoCheck will not validate current data.  the constraint will force all incoming data (insert or update) to be 8 chars in length.

Syntax should be:

ALTER TABLE <TABLE> WITH NOCHECK ADD CONSTRAINT
      <NAME_OF_CONSTRAINT> CHECK (DATALENGTH([<COLUMN>]) = 8)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
25112Author Commented:
i got it now.. thanks ged325!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.