Mysql Column constraint as "not empty" / "required" -


can specify column in mysql "not empty" / "required". requirement ensure field never remains blank on record insertion.

i assume don't want blank (empty string, opposed null) values allowed in table either.

normally, that's check constraint for. like

create table         mytable         (         myfield not null varchar(200),         check(myfield > '')         ) 

however, mysql parses constraint not enforce it. still allowed insert empty values.

to work around that, create before insert trigger , raise signal on attempt insert blank value:

create trigger         tr_mytable_bi before insert on      mytable each row begin         if new.myfield = ''                 signal sqlstate '45001' set message_text = 'blank value on mytable.myfield';         end if; end; 

do same on before update if want forbid updates blank value well.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -