输入内容中必须有@,用什么约束啊!还有输入的数字是8位数,用什么约束!!在线等。。急

解决方案 »

  1.   

    好像跟sql没啥关系?
    web页面的话,考虑下 正则表达式
      

  2.   

    alter table tb add constraint ck_name check(col_name like '[@][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
      

  3.   

    declare @t table(test varchar(10) check(charindex('@',test)>0))
    insert @t select 'sdf@'
    insert @t select 'a'
    /*
    (影響 1 個資料列)伺服器: 訊息 547,層級 16,狀態 1,行 3
    INSERT 陳述式與 COLUMN CHECK 條件約束 'CK__@t__test__0DAF0CB0' 發生衝突。衝突發生於資料庫 'tempdb',資料表 '#0CBAE877', column 'test'。
    陳述式已經結束。
    */
      

  4.   

    create table T(col varchar(20))alter table t add constraint ck_name check(col like '[@][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')insert T select '@12345678'
    select * from Tdrop table Tcol                  
    -------------------- 
    @12345678(所影响的行数为 1 行)
      

  5.   

    create table T(col varchar(20))alter table t add constraint ck_name check(col like '[@][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')insert T select '@1234567A'
    select * from Tdrop table T服务器: 消息 547,级别 16,状态 1,行 1
    INSERT 语句与 COLUMN CHECK 约束 'ck_name' 冲突。该冲突发生于数据库 'pubs',表 'T', column 'col'。
    语句已终止。
    col                  
    -------------------- (所影响的行数为 0 行)