create table cardInfo
(
cardID varchar(20) not null,
curType char(10) not null,
savingType char(10),
openDate datetime not null,
openMoney money not null,
balance money not null,
pass char(8) not null,
IsReportLoss bit not null,
customerID int not null
)/*---约束---*/
alter table cardInfo
add constraint pk_cardID primary key(cardID)
alter table cardInfo
add constraint ck_cardID check(cardID like '1010 3576 [0-9][0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
/*--数据--*/
insert into cardInfo(cardID,savingType,openMoney,balance,pass,customerID) values('1010 3576 1234 5678','活期',1000,1000,'888888',1)
insert into cardInfo(cardID,savingType,openMoney,balance,pass,customerID) values('1010 3567 1212 1134','定期',1,1,'888888',2)
第一条可以插进去,第二条就不行了.
错误是:INSERT 语句与 CHECK 约束"ck_cardID"冲突。该冲突发生于数据库"bankDB",表"dbo.cardInfo", column 'cardID'。
我怎么也看不出是哪里出错了.
请高人帮我看看!谢了!

解决方案 »

  1.   


    insert into cardInfo(cardID,savingType,openMoney,balance,pass,customerID) values('1010 3567 1212 1134','定期',1,1,'888888',2) 
    --不应该是3576么?:)
      

  2.   

    insert into cardInfo(cardID,savingType,openMoney,balance,pass,customerID) values('1010 3576 1212 1134','定期',1,1,'888888',2) 
      

  3.   

    晕,格式没对values('1010 3567 1212 1134',.....
    --这里的第2组数据,应该必须是3576,不是3567,太粗心了
      

  4.   

    虽然自己不懂也在学习中,可是我觉得不能插入相同的cardID吧,呵呵,要是有正确答案告诉我啊!
      

  5.   

    check(cardID like '1010 3576 [0-9][0-9][0-9][0-9] [0-9][0-9][0-9][0-9]') 
    values('1010 3567 1212 1134',) 
      

  6.   

    楼主朋友,第2条插入语句中cardID第7,8位与约束的不对,所以出现了那个提示,应该改为 3576 就可以了吧.