mysql-error-1442

Find node level in a tree

那年仲夏 提交于 2019-12-05 07:26:38
I have a tree (nested categories) stored as follows: CREATE TABLE `category` ( `category_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `category_name` varchar(100) NOT NULL, `parent_id` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`category_id`), UNIQUE KEY `category_name_UNIQUE` (`category_name`,`parent_id`), KEY `fk_category_category1` (`parent_id`,`category_id`), CONSTRAINT `fk_category_category1` FOREIGN KEY (`parent_id`) REFERENCES `category` (`category_id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci I need to feed my client-side

MySql Triggers to delete child records in the same table

你离开我真会死。 提交于 2019-12-02 05:33:26
问题 I have a table that stores parent and child records in it. I was trying to create a trigger that would delete all child records when the parent is deleted: Delete From tbl Where ParentId = OLD.Id While I can save the trigger successfully, when deleting I get this error: ERROR 1442: Can’t update table ‘tbl′ in stored function/trigger because it is already used by statement which invoked this What am I doing wrong? 回答1: It appears that this is not possible: You cannot DELETE rows in the table

MySQL: How to create trigger for setting creation date for new rows

南笙酒味 提交于 2019-11-30 03:49:30
I ran into a problem as I tried to create two TIMESTAMP columns in my database. One called created and one called updated . I figured it would be easy to set the default value of both to CURRENT_TIMESTAMP and then ON UPDATE CURRENT_TIMESTAMP for the updated column. But for some reason MySQL means that's a bad idea... so I have been looking for ways to do this without having to set one of them in the insert query. I found one way by using a trigger in this answer , but I keep getting errors. I just managed to actually create the trigger, but now I get errors when I try to insert new rows

what is the real cause of mysql error 1442?

老子叫甜甜 提交于 2019-11-27 09:44:23
well i have looked for a lot of places on the internet for the cause of the mysql error #1442 which says Can't update table 'unlucky_table' in stored function/trigger because it is already used by statement which invoked this stored function/trigger some say that this is a bug in mysql or a feature that it doesnt provide. MySQL triggers can't manipulate the table they are assigned to. All other major DBMS support this feature so hopefully MySQL will add this support soon. Some claim that this is due to recursive behavior when you insert a record mysql is doing some lock stuff. you can't insert

Updating table in trigger after update on the same table

六月ゝ 毕业季﹏ 提交于 2019-11-27 09:25:43
How can I update table's column in a trigger after update on the same table? Here's the trigger: CREATE TRIGGER upd_total_votes AFTER UPDATE ON products_score FOR EACH ROW UPDATE products_score SET products_score.votes_total = (SELECT (votes_1 + votes_2 + votes_3 + votes_4 + votes_5) FROM products_score WHERE id = new.id) Now when I update the table like UPDATE products_score SET votes_1 = 5 WHERE id = 0 this doesn't work, as I get the following: #1442 - Can't update table 'products_score' in stored function/trigger because it is already used by statement which invoked this stored function

How to Update same table on deletion in MYSQL?

社会主义新天地 提交于 2019-11-27 05:46:00
问题 In my database I have a table Employee that has recursive association (an employee can be boss of other employee): create table if not exists `employee` ( `SSN` varchar(64) not null, `name` varchar(64) default null, `designation` varchar(128) not null, `MSSN` varchar(64) default null, primary key (`ssn`), constraint `fk_manager_employee` foreign key (`mssn`) references employee(ssn) ) engine=innodb default charset=latin1;   mysql> describe Employee; +-------------+--------------+------+-----+

mysql trigger stored trigger is already used by statement which invoked stored trigger

对着背影说爱祢 提交于 2019-11-26 21:01:50
I want to set up a trigger so that if on an update the prediction field is = 3 then the trigger changes the value to 4 and saves it in the database. The trigger is below. For some reason I keep getting an error saying: #1442 - Can't update table 'tzanalytic\_forecast\_cached' in stored function/trigger because it is already used by statement which invoked this stored function/trigger. Is this set up the right way? delimiter $$ CREATE TRIGGER no_BoW BEFORE UPDATE ON t FOR EACH ROW BEGIN set @prediction = new.prediction; UPDATE t SET t.prediction = (SELECT IF(@prediction = '3', '4', @prediction)

Updating table in trigger after update on the same table

别等时光非礼了梦想. 提交于 2019-11-26 14:41:40
问题 How can I update table's column in a trigger after update on the same table? Here's the trigger: CREATE TRIGGER upd_total_votes AFTER UPDATE ON products_score FOR EACH ROW UPDATE products_score SET products_score.votes_total = (SELECT (votes_1 + votes_2 + votes_3 + votes_4 + votes_5) FROM products_score WHERE id = new.id) Now when I update the table like UPDATE products_score SET votes_1 = 5 WHERE id = 0 this doesn't work, as I get the following: #1442 - Can't update table 'products_score' in