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) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

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

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