Trigger to fail query
How to create trigger (mysql) which to fail sql query if some of fields have no data ?
Here is my table
CREATE TABLE `new` (
`id` int(11) DEFAULT NULL,
`name` int(11) DEFAULT NULL,
`phone` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Let`s say I have this quer开发者_开发知识库y
INSERT INTO new values(1, 'Bu', '');
I want that query to fail if there is no data for phone field.
phone field is declared as int so you are sending and empty char use this
INSERT INTO new values(1, 'Bu', o);
You may change the property of phone to varchar() or at least remove the NOT NULL property so you can insert null values.
INSERT INTO new values(1, 'Bu', NULL);
or
INSERT INTO new (`id`, `name`) values(1, 'Bu');
精彩评论