stuName 学生姓名,要考虑姓氏可能是两个字的,如欧阳 
添加约束 主要是条件怎么写

解决方案 »

  1.   

    --> 测试数据:  tb
    if object_id('tb') is not null drop table tb
    go
    create table tb (stuName varchar(10) )alter table tb add constraint check_len check(len(stuName)<=2)insert into tb select '我'
    insert into tb select '我的'
    insert into tb select '我速度'(1 行受影响)(1 行受影响)
    消息 547,级别 16,状态 0,第 9 行
    INSERT 语句与 CHECK 约束"check_len"冲突。该冲突发生于数据库"szy",表"dbo.tb", column 'stuName'。
    语句已终止。