SQL语法中的check在MySQL中无效,在MySQL中怎么实现SQL标准语法中的che...
发布网友
发布时间:2022-05-06 07:00
我来回答
共2个回答
热心网友
时间:2022-04-15 19:45
mysql> create table student
-> (sno enum
-> ('1','2','3','4','5','6','7','8','9','10',
-> '11','12','13','14','15','16','17','18','19','20',
-> '21','22','23','24','25','26','27','28','29','30',
-> '31','32','33','34','35','36','37','38','39','40',
-> '41','42','43','44','45','46','47','48','49','50',
-> '51','52','53','54','55','56','57','58','59','60',
-> '61','62','63','64','65','66','67','68','69','70',
-> '71','72','73','74','75','76','77','78','79','80',
-> '81','82','83','84','85','86','87','88','89','90',
-> '91','92','93','94','95','96','97','98','99','100')
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> insert into student values(99);
Query OK, 1 row affected (0.03 sec)
mysql> insert into student values(100);
Query OK, 1 row affected (0.05 sec)
mysql> insert into student values(101);
ERROR 1265 (01000): Data truncated for column 'sno' at row 1
如果遇到更加复杂的Check, 那就只好触发器了。
MySQL 好像还没有自定义异常。
所以,你想输出提示 "插入数据失败" 恐怕也不行。追问不会吧 我老师就行,就是我老师给我出的题目。
热心网友
时间:2022-04-15 21:03
你可以在sql语句里面用js验证嘛,如果连接到页面就弹出对话框“插入数据成功”else否则“插入数据库失败”,你试试吧,作为参考,呵呵