check约束好像不起作用啊?!情况如下:mysql> create table t (c1 integer check (c1 < 50));
Query OK, 0 rows affected (0.03 sec)mysql> insert into t values(20);
Query OK, 1 row affected (0.00 sec)mysql> insert into t values(60);
Query OK, 1 row affected (0.00 sec)mysql> select * from t;
+------+
| c1   |
+------+
|   20 |
|   60 |
+------+
2 rows in set (0.00 sec)怎么回事?谢谢!

解决方案 »

  1.   

    以下摘自 MySQL 5.1 Reference ManualThe CHECK clause is parsed but ignored by all storage engines. 聋子的耳朵,摆设[align=center]====  ====
    [/align]
      

  2.   

    以下摘自 MySQL 5.1 Reference ManualThe FOREIGN KEY and REFERENCES clauses are supported by the InnoDB storage engine
    For other storage engines, the clauses are parsed but ignored. The CHECK clause is parsed but ignored by all storage engines. 
    The reason for accepting but ignoring syntax clauses is for compatibility, to make it easier to port code from other SQL servers, and to run applications that create tables with references.[align=center]====  ====
    [/align]
      

  3.   

    check约束只起到注释的作用。
    MYSQL加了这个只是为了对移植到其他数据库提供方便。
      

  4.   

    那我怎么对我的数据库表在mysql里添加约束啊?
     难道不能添加了吗??????
      

  5.   

     难道不能添加了吗?????? 是的,mySQL不支持check constraint.[align=center]====  ====
    [/align]
      

  6.   

    晕  范围检查 这么重要的功能mysql都没有?
    那我要建个 范围在100-200的int型数据 别人输入201就会报错
     岂不是不可能?
      

  7.   

    如果想实现 只能换个数据库吗? 1. 在你的程序中实现
    2. 换数据库[align=center]====  ====
    [/align]
      

  8.   

    用触发器检查吧。但是必须是前置触发器处理befor insert