MySQL中的断言 [英] Assertion in MySQL

查看:585
本文介绍了MySQL中的断言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个针对大型数据库运行的SQL脚本.我想一开始就进行几个简单的查询,就像进行健全性检查一样.

I have a SQL script to run against a large database. I'd like to put a couple of simple queries at the start, just as a sanity check.

有什么方法可以在MySQL中编写断言吗?还是任何一种选择...,如果它与该值不匹配,则中止整个脚本"?

Is there any way to write an assertion in MySQL? Or any kind of "select ..., and if it doesn't match this value, then abort the entire script"?

推荐答案

一些疯狂的代码.要点是:SET可能引发mysql变量错误.

Some crazy code. Main point is: SET could raise error for mysql variables.

例如.

 SET @value = 0;
 SET SESSION sql_mode = if(@value, @@SESSION.sql_mode, 'something wrong uphere'); 

将输出ERROR 1231 (42000): Variable 'sql_mode' can't be set to the value of 'something wrong uphere'并停止执行.

这种方法不是语义上的,但可以.

This approach is not semantic but it works.

这篇关于MySQL中的断言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆