我正在使用MySQL 5.1.36我正在尝试删除名为chk1
的约束,但MySQL会报告语法错误。我查了一下却无法找到它。错误是什么?
mysql> create database house;
Query OK, 1 row affected (0.01 sec)
mysql> use house;
Database changed
mysql> create table member(age integer);
Query OK, 0 rows affected (0.05 sec)
mysql> alter table member add constraint chk1 check(age>0);
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table member drop constraint chk1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'constraint chk1' at line 1
mysql> alter table member drop check chk1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'check chk1' at line 1
答案 0 :(得分:2)
检查约束被解析但在Mysql中被忽略。所以你不需要删除它。您可以使用枚举或触发器来实现所需的功能。在您的情况下,您还可以将age
更改为unsigned
。