当前位置:Gxlcms > 数据库问题 > Check restriction for mysql

Check restriction for mysql

时间:2021-07-01 10:21:17 帮助过:10人阅读

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:

  1. trigger-name: credit_tri

  2. target-table:student

  3. target-field:IDCard

  4. 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

标签:text   check   arc   iter   hive   log   idc   -name   code   

人气教程排行