Check restriction for mysql
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Check restriction for mysql相关的知识,希望对你有一定的参考价值。
Check restriction for mysql
Mysql does not suppot for check restriction but oracle does. Here using trigger we can achive the same restrction as check does.
Scenario:
Here is a IDcard field in table student with a restriction that the length of IDCrad must less than 18.
4 parameters we can use:
-
trigger-name: credit_tri
-
target-table:student
-
target-field:IDCard
-
error-msg:"length is above 18,cannot insert"
mysql> delimiter $ mysql> create trigger credit_tri before insert -> on student for each row -> begin -> declare msg varchar(200); -> if (new.IDCard > 18) then -> set msg = "length is above 18. Cannot insert."; -> signal sqlstate ‘HY000‘ SET message_text = msg; -> end if; -> end $
以上是关于Check restriction for mysql的主要内容,如果未能解决你的问题,请参考以下文章
使用 Restriction for Ionic 应用程序保护 Google Maps API 密钥
sql fix_access_denied_for_user_in_mysql.sql