Home > database >  Could you tell me how to be more elegant design database synchronization problem? This example is to
Could you tell me how to be more elegant design database synchronization problem? This example is to

Time:09-27

 DELIMITER $$
USE ` a `; $$
DROP the TRIGGER IF the EXISTS ` a `. ` aai `; $$
CREATE the TRIGGER ` a `. ` aai `
AFTER INSERT ON ` a `. ` aa `
FOR EACH ROW
The BEGIN
IF (new. ` servers `='b' AND new. The type=0) THEN
INSERT INTO ` c `. ` cc ` (` uuid `, ` type `, ` servers `, ` name `) VALUES (new uuid, new type, new. ` servers `, new. ` name `);
INSERT INTO ` d `. ` dd ` (` uuid `, ` type `, ` servers `, ` name `) VALUES (new uuid, new type, new. ` servers `, new. ` name `);
END IF;
IF (new. ` servers `='c' AND new. The type=0) THEN
INSERT INTO ` ` b. ` bb ` (` uuid `, ` type `, ` servers `, ` name `) VALUES (new uuid, new type, new. ` servers `, new. ` name `);
INSERT INTO ` d `. ` dd ` (` uuid `, ` type `, ` servers `, ` name `) VALUES (new uuid, new type, new. ` servers `, new. ` name `);
END IF;
IF (new. ` servers `='d' AND new. The type=0) THEN
INSERT INTO ` ` b. ` bb ` (` uuid `, ` type `, ` servers `, ` name `) VALUES (new uuid, new type, new. ` servers `, new. ` name `);
INSERT INTO ` c `. ` cc ` (` uuid `, ` type `, ` servers `, ` name `) VALUES (new uuid, new type, new. ` servers `, new. ` name `);
END IF;
END; $$

DELIMITER $$

USE ` a `; $$
DROP the TRIGGER IF the EXISTS ` a `. ` aau `; $$
CREATE the TRIGGER ` a `. ` aau ` AFTER the UPDATE
ON ` a `. ` aa ` FOR EACH ROW
The BEGIN
IF (new. ` servers `='b' AND new. The type=0) THEN
UPDATE ` c `. ` cc ` SET ` uuid `.=new uuid, ` type `=new. ` type `, ` servers `.=new servers, ` name `=new. Name the WHERE ` uuid `.=new uuid;
UPDATE ` d `. ` dd ` SET ` uuid `.=new uuid, ` type `=new. ` type `, ` servers `.=new servers, ` name `=new. Name the WHERE ` uuid `.=new uuid;
END IF;
IF (new. ` servers `='c' AND new. The type=0) THEN
UPDATE ` ` b. ` bb ` SET ` uuid `.=new uuid, ` type `=new. ` type `, ` servers `.=new servers, ` name `=new. Name the WHERE ` uuid `.=new uuid;
UPDATE ` d `. ` dd ` SET ` uuid `.=new uuid, ` type `=new. ` type `, ` servers `.=new servers, ` name `=new. Name the WHERE ` uuid `.=new uuid;
END IF;
IF (new. ` servers `='d' AND new. The type=0) THEN
UPDATE ` ` b. ` bb ` SET ` uuid `.=new uuid, ` type `=new. ` type `, ` servers `.=new servers, ` name `=new. Name the WHERE ` uuid `.=new uuid;
UPDATE ` c `. ` cc ` SET ` uuid `.=new uuid, ` type `=new. ` type `, ` servers `.=new servers, ` name `=new. Name the WHERE ` uuid `.=new uuid;
END IF;
END;
$$


DELIMITER $$
USE ` a `; $$
DROP the TRIGGER IF the EXISTS ` a `. ` aad `; $$
CREATE the TRIGGER ` a `. ` aad ` AFTER DELETE
ON ` a `. ` aa ` FOR EACH ROW
The BEGIN
IF (OLD. ` servers `='b' AND OLD. Type=0) THEN
The DELETE FROM ` c `. ` cc ` WHERE ` uuid `=OLD. Uuid;
The DELETE FROM ` d `. ` dd ` WHERE ` uuid `=OLD. Uuid;
END IF;
IF (OLD. ` servers `='c' AND OLD. Type=0) THEN
The DELETE FROM ` ` b. ` bb ` WHERE ` uuid `=OLD. Uuid;
The DELETE FROM ` d `. ` dd ` WHERE ` uuid `=OLD. Uuid;
END IF;
IF (OLD. ` servers `='d' AND OLD. Type=0) THEN
The DELETE FROM ` c `. ` cc ` WHERE ` uuid `=OLD. Uuid;
The DELETE FROM ` d `. ` dd ` WHERE ` uuid `=OLD. Uuid;
END IF;
END;
$$

DELIMITER $$
USE ` ` b; $$
DROP the TRIGGER IF the EXISTS ` ` b. ` bbi `; $$
CREATE the TRIGGER ` ` b. ` bbi `
BEFORE the INSERT ON ` ` b. ` bb `
FOR EACH ROW
The BEGIN
IF (new. ` servers `='b') THEN
INSERT INTO ` a `. ` aa ` (` uuid `, ` type `, ` servers `, ` name `) VALUES (new uuid, new type, new. ` servers `, new. ` name `);
END IF;
END; $$

DELIMITER $$
USE ` ` b; $$
DROP the TRIGGER IF the EXISTS ` ` b. ` BBD `; $$
CREATE the TRIGGER ` ` b. ` BBD ` AFTER DELETE
ON ` ` b. ` bb ` FOR EACH ROW
The BEGIN
IF (OLD. ` servers `='b') THEN
The DELETE FROM ` a `. ` aa ` WHERE ` uuid `=OLD. Uuid;
END IF;
END;
$$

DELIMITER $$
USE ` ` b; $$
DROP the TRIGGER IF the EXISTS ` ` b. ` bbu `; $$
CREATE the TRIGGER ` ` b. ` bbu ` AFTER the UPDATE
ON ` ` b. ` bb ` FOR EACH ROW
The BEGIN
IF (new. ` servers `='b') THEN
UPDATE ` a `. ` aa ` SET ` uuid `.=new uuid, ` servers `.=new servers, ` name `=new. Name the WHERE ` uuid `.=new uuid;
END IF;
END;
$$

DELIMITER $$
USE ` c `; $$
DROP the TRIGGER IF the EXISTS ` c `. ` cci `; $$
CREATE the TRIGGER ` c `. ` cci `
BEFORE the INSERT ON ` c `. ` cc `
FOR EACH ROW
The BEGIN
IF (new. ` servers `='c') THEN
INSERT INTO (` uuid `, ` type `, ` servers `, ` name `) VALUES (new uuid, new type, new. ` servers `, new. ` name `);
END IF;
END; $$


DELIMITER $$
USE ` c `; $$
DROP the TRIGGER IF the EXISTS ` c `. ` CCD `; $$
CREATE the TRIGGER ` c `. ` CCD ` AFTER DELETE
ON ` c `. ` cc ` FOR EACH ROW
The BEGIN
IF (OLD. ` servers `='c') THEN
The DELETE FROM ` a `. ` aa ` WHERE ` uuid `=OLD. Uuid;
END IF;
END;
$$

DELIMITER $$
USE ` c `; $$
DROP the TRIGGER IF the EXISTS ` c `. ` ccu `; $$
CREATE the TRIGGER ` c `. ` ccu ` AFTER the UPDATE
ON ` c `. ` cc ` FOR EACH ROW
The BEGIN
IF (new. ` servers `='c') THEN
UPDATE ` a `. ` aa ` SET ` uuid `.=new uuid, ` servers `.=new servers, ` name `=new. Name the WHERE ` uuid `.=new uuid;
END IF;
END;
$$


DELIMITER $$
USE ` d `; $$
DROP the TRIGGER IF the EXISTS ` d `. ` ddi `; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related