CHECK

  • How can I write a check constraint to prevent entering characters below char(32) (space) on a column of a table?

  • CHECK (LEN(RTRIM(LTRIM(columnName))) >= 32)

    I would also suggest you to please go through the CREATE TABLE syntax in BOL.

    -Vikas Bindra

  • What is the Column Definition?

  • I have tested this one:

    CREATE TABLE tbl (

    id int IDENTITY,

    col varchar(50) CONSTRAINT CK_t1 CHECK (col not like '%[^ -~A-Z0-9]%')

    )

    and when i try these insert statements:

    INSERT INTO tbl(col) VALUES('abc' + char(20))

    INSERT INTO tbl(col) VALUES('abc' + char(9))

    the first one fails correctly but the second runs successfully.

    this check constraint suppress all characters below asccii 32 execpt char(9) to char(13). and i dont know why. by the way i want to let characters upper than ~ could be inserted too. how can i do it?

  • I can't say that I like this solution but it is an option to consider

    You write the check constraint CHECK ( dbo.udfCheckInput(col) = 1)

    The user function checks that the ascii value of each character in the column is not below 32.....

    Sorry I can't send code again

Viewing 5 posts - 1 through 4 (of 4 total)

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