A
A
alpa_kz2018-04-04 07:01:12
MySQL
alpa_kz, 2018-04-04 07:01:12

How to create a mysql trigger to update a table in another database?

creation of tables test DB billing;

USE billing;
CREATE TABLE `test` (
`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`content` TEXT NOT NULL 
) ENGINE = innodb;

creating a test table in another database billing_test
USE billing_test;
CREATE TABLE `test` (
`id` INT( 11 ) UNSIGNED NOT NULL PRIMARY KEY,
`content` TEXT NOT NULL 
) ENGINE = innodb;

Trigger updates on insert another table in another table
use billing;
DELIMITER //
CREATE TRIGGER `update_test3` AFTER INSERT ON `test`
FOR EACH ROW 
BEGIN
   INSERT INTO `billing_test.test` set id = NEW.ID, content = NEW.content;
-- как правильно здесь указать таблицу из другой базы??????
END; 
//
DELIMITER ;

at insert
INSERT INTO billing.test(content) VALUE("TEST NEW TRIGEER");

gives this error(
->
Table 'billing.billing_test.test' doesn't exist C:\Users\UserA\Documents\SQL.sql

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2018-04-04
@alpa_kz

`billing_test.test` is the name of the table in the current database
`billing_test`.`test` is the test table in the billing_test database

A
Alex McArrow, 2018-04-04
@AlexMcArrow

Perhaps your code is just an example, but it has syntactical problems
The INSERT code should look different (in a trigger)
"Might help"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question