MySQL - check使用

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: MySQL - check使用

在使用MySQL时,不经意用到了check来约束,结果发件加不加check没区别,所以就查找了下资料,发现MySQL目前不被支持,这么说MySQL的路还有很长啊。


但是如果想要用到的话,网上提供了两种方法:


1.使用枚举,不过博主在试了下,要实现限制范围,就必须把这个范围内的所有数写进枚举,实际开发中,这无疑是不可取的,范围小的时候可考虑;

create table test5(test1Id int,testname varchar(50),testpass varchar(50),sal enum(1,2,3,4,5));

2.使用触发器,每一个表中,触发器有且只能有一个

 CREATE TRIGGER testref AFTER INSERT ON test6
  FOR EACH ROW BEGIN
    if NEW.test1Id>100  then
       delete from test6 where test1Id=NEW.test1Id;
    end if ;

这里要说明的是,一般我们可以在插入数据之前做判断,不需要写在数据库中。

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
4月前
|
SQL 数据采集 关系型数据库
如何解决MySQL报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL?
如何解决MySQL报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL?
|
7月前
|
SQL 关系型数据库 MySQL
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
错误提示: Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; che
91 0
|
5月前
|
SQL 关系型数据库 MySQL
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
29 0
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
|
6月前
|
关系型数据库 MySQL Linux
DVWA CentOS Could not connect to the MySQL service. Please check the config file.
DVWA CentOS Could not connect to the MySQL service. Please check the config file.
39 0
|
9月前
|
SQL 关系型数据库 MySQL
check the manual that corresponds to your MySQL server version for the right syntax to use near lin
注意这种一般情况下是语法问题,说明mysql的各种语句还是不够熟练, (1)看表名是不是使用了Mysql的关键字,如果是,请立马改掉; (2)语句给出哪里错误,如我的题目中给出“near”,说明在那附近有问题。 (3)检查mybatis中mapper里sql语句占位符是否写对,我的问题是将#{name}写成了#(name),尴尬。
134 0
|
10月前
|
XML 关系型数据库 MySQL
已解决Failed to connect mysql database,please check username and password,or mysql is version8? true
已解决Failed to connect mysql database,please check username and password,or mysql is version8? true
145 0
|
11月前
|
SQL 关系型数据库 MySQL
修改mysql的密码时遇到问题ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corre
修改mysql的密码时遇到问题ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corre
|
12月前
|
SQL 关系型数据库 MySQL
MySQL中sp运行check表版本更新流程解析
MySQL中sp运行check表版本更新流程解析
205 0
|
SQL 关系型数据库 MySQL
springboot-plus 导入starter-mysql.sql时出现[Err] 1064 - You have an error in your SQL syntax; check the
springboot-plus 导入starter-mysql.sql时出现[Err] 1064 - You have an error in your SQL syntax; check the
110 0
springboot-plus 导入starter-mysql.sql时出现[Err] 1064 - You have an error in your SQL syntax; check the
|
关系型数据库 MySQL 分布式数据库
#bug68021 MySQL unique check 的问题
unique secondary index 是客户经常使用的场景, 用来保证index 上的record 的唯一性. 但是大量的客户在使用unique secondary index 以后会发现偶尔会有死锁或者不应该锁等待的时候却发生锁等待的情况. 也有很多客户来问我们这个问题. 理论上PolarDB 默认使用read-commit isolation level, 在rc 隔离级别下绝
118 0