Constraint syntax

  • Found out I could not do a rule so i need a constraint on a varchar(5) field that can contain null or up to 5 numbers including leading zeroes. What I tried is

    ALTER TABLE dbo.person_test2 ADD CONSTRAINT CK_ext

    check (Pext like '[0-9][0-9][0-9][0-9][0-9]')

    problem is it forces null and has to be 5 characters

  • ALTER TABLE dbo.person_test2

    ADD CONSTRAINT CK_ext

    CHECK ( Pext LIKE REPLICATE('[0-9]', LEN(Pext)) )

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply