MySQL - check使用

简介: 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 ;

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

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
目录
相关文章
|
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?
15015 2
|
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
530 0
|
关系型数据库 MySQL
【MySQL进阶之路 | 基础篇】约束之CHECK约束与DEFAULT约束
【MySQL进阶之路 | 基础篇】约束之CHECK约束与DEFAULT约束
|
SQL 关系型数据库 MySQL
You have an error in your SQL syntax;check the manual that corresponds to you Mysql server version
You have an error in your SQL syntax;check the manual that corresponds to you Mysql server version
|
SQL 存储 关系型数据库
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
|
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
|
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
1117 0
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
|
关系型数据库 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.
402 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
473 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 隔离级别下绝
423 0

推荐镜像

更多