我现在有个字段的长度设置为8位,我想实现该字段输入时必须是8位并且是数字,怎么实现?就是说少于8位的不允许输入,中间含有非数字的字符也不允许输入,有没有办法设置数据库?

解决方案 »

  1.   

    if len(rtrim(ltrim(串))) = 8 and isnumeric(rtrim(ltrim(串))) = 1 then ok
      

  2.   

    len(columnname)=8 长度=8的
    ISNUMERIC ( columnname) =1  非数字
      

  3.   

    觉得不应该rtrim,ltrim应该直接这样:
    if len(串) = 8 and isnumeric(串) = 1 then ok
      

  4.   

    数值是什么形式的?00000000,有这种形式么?如果没有,是否可以:
    改成int型,然后设置最小值10000000和最大值99999999
      

  5.   

    添加一个约束create table test(a varchar(8) )alter table test add constraint chid check (a like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
      

  6.   

    create table test(
    test varchar(8)
    CONSTRAINT CK_test_test check (test like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
    )