Created
July 27, 2016 02:53
-
-
Save yoku0825/83d723a13b532caf6314496fe72e9007 to your computer and use it in GitHub Desktop.
[mysql 16354] 一つのイベントに対して複数のSQLを実行するTRIGGERを定義したい
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>bin\mysqldump --triggers -uroot d1 | |
-- MySQL dump 10.13 Distrib 5.6.31, for Win64 (x86_64) | |
-- | |
-- Host: localhost Database: d1 | |
-- ------------------------------------------------------ | |
-- Server version 5.6.31 | |
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | |
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | |
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | |
/*!40101 SET NAMES utf8 */; | |
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | |
/*!40103 SET TIME_ZONE='+00:00' */; | |
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | |
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | |
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | |
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; | |
-- | |
-- Table structure for table `child_table` | |
-- | |
DROP TABLE IF EXISTS `child_table`; | |
/*!40101 SET @saved_cs_client = @@character_set_client */; | |
/*!40101 SET character_set_client = utf8 */; | |
CREATE TABLE `child_table` ( | |
`id` int(11) DEFAULT NULL, | |
`p_id` int(11) DEFAULT NULL, | |
`lastupdtime` datetime DEFAULT NULL, | |
`data` text, | |
KEY `p_id` (`p_id`), | |
CONSTRAINT `child_table_ibfk_1` FOREIGN KEY (`p_id`) REFERENCES `parent_table` (`id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | |
/*!40101 SET character_set_client = @saved_cs_client */; | |
-- | |
-- Dumping data for table `child_table` | |
-- | |
LOCK TABLES `child_table` WRITE; | |
/*!40000 ALTER TABLE `child_table` DISABLE KEYS */; | |
/*!40000 ALTER TABLE `child_table` ENABLE KEYS */; | |
UNLOCK TABLES; | |
/*!50003 SET @saved_cs_client = @@character_set_client */ ; | |
/*!50003 SET @saved_cs_results = @@character_set_results */ ; | |
/*!50003 SET @saved_col_connection = @@collation_connection */ ; | |
/*!50003 SET character_set_client = utf8 */ ; | |
/*!50003 SET character_set_results = utf8 */ ; | |
/*!50003 SET collation_connection = utf8_general_ci */ ; | |
/*!50003 SET @saved_sql_mode = @@sql_mode */ ; | |
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; | |
DELIMITER ;; | |
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `child_table_AFTER_UPDATE` AFTER UPDATE ON `child_table` FOR EACH ROW | |
BEGIN | |
update parent_table set lastupdtime = sysdate() where id = old.p_id; | |
update child_table set lastupdtime = sysdate() where new.data <> old.data; | |
END */;; | |
DELIMITER ; | |
/*!50003 SET sql_mode = @saved_sql_mode */ ; | |
/*!50003 SET character_set_client = @saved_cs_client */ ; | |
/*!50003 SET character_set_results = @saved_cs_results */ ; | |
/*!50003 SET collation_connection = @saved_col_connection */ ; | |
-- | |
-- Table structure for table `parent_table` | |
-- | |
DROP TABLE IF EXISTS `parent_table`; | |
/*!40101 SET @saved_cs_client = @@character_set_client */; | |
/*!40101 SET character_set_client = utf8 */; | |
CREATE TABLE `parent_table` ( | |
`id` int(11) NOT NULL DEFAULT '0', | |
`p_id` int(11) DEFAULT NULL, | |
`lastupdtime` datetime DEFAULT NULL, | |
`data` text, | |
PRIMARY KEY (`id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | |
/*!40101 SET character_set_client = @saved_cs_client */; | |
-- | |
-- Dumping data for table `parent_table` | |
-- | |
LOCK TABLES `parent_table` WRITE; | |
/*!40000 ALTER TABLE `parent_table` DISABLE KEYS */; | |
/*!40000 ALTER TABLE `parent_table` ENABLE KEYS */; | |
UNLOCK TABLES; | |
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | |
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | |
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | |
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | |
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | |
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | |
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | |
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; | |
-- Dump completed on 2016-07-27 11:51:48 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment