Skip to content

Instantly share code, notes, and snippets.

@markbalt
Created June 2, 2015 19:03
Show Gist options
  • Save markbalt/ddb4a48b4e685e7f2a1b to your computer and use it in GitHub Desktop.
Save markbalt/ddb4a48b4e685e7f2a1b to your computer and use it in GitHub Desktop.
Visitor MySQL Trigger
DROP TRIGGER IF EXISTS `visitor_insert_t`;
DELIMITER ;;
CREATE TRIGGER `visitor_insert_t` AFTER INSERT ON `visitor` FOR EACH ROW BEGIN
IF NEW.arrival_date IS NOT NULL THEN
INSERT INTO `visit`(
`visitor_id`,
`location_id`,
`customer_id`,
`customer_name`,
`arrival_date`,
`depart_date`,
`expire_date`,
`has_arrived`,
`host_name`,
`host_email`,
`is_active`,
`purpose`,
`verified_date`,
`verified_by`
)
VALUES
(
NEW.id,
NEW.location_id,
NEW.customer_id,
NEW.customer_name,
NEW.arrival_date,
NEW.depart_date,
NEW.expire_date,
NEW.has_arrived,
NEW.host_name,
NEW.host_email,
NEW.is_active,
NEW.purpose,
NULL,
NULL
);
END
IF ;
END
;;
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment