简体   繁体   中英

Syntax error defining triggers in mysql 5.0.77

CREATE TABLE `applications` (
`id` int(2) NOT NULL,
`applicationID` varchar(36) character set utf8 collate utf8_unicode_ci NOT NULL,
`applicationType` enum('M','W') character set utf8 collate utf8_unicode_ci NOT NULL,
`applicationName` varchar(30) character set utf8 collate utf8_unicode_ci NOT NULL,
`applicationPath` varchar(100) character set utf8 collate utf8_unicode_ci NOT NULL,
`isDeleted` tinyint(1) NOT NULL default '0',
`lastModified` timestamp NOT NULL default CURRENT_TIMESTAMP
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

-- -- Dumping data for table applications --

 INSERT INTO `applications` (`id`, `applicationID`, `applicationType`, `applicationName`,     `applicationPath`, `isDeleted`, `lastModified`) VALUES (1, 'a49af37e-7f4c-1032-a010-   c067c39cc60b', 'W', 'workshopWorkerWeb',   'http://www.workshopworker.com/workshopWorkerLogin/workshopWorkerLogin.html', 0, '2014-08-27   15:11:46'),
(2, 'a49af5c2-7f4c-1032-a010-c067c39cc60b', 'W', 'agriMapper', '', 0, '2014-08-27 15:11:46'),
(3, 'a49af702-7f4c-1032-a010-c067c39cc60b', 'M', 'promacRegistration',  'https://play.google.com/store/apps/details?id=com.ncbaclusapromac.ncbaclusapromac', 0, '2014-08-27 15:11:46'),
(4, 'a49af838-7f4c-1032-a010-c067c39cc60b', 'M', 'eBAF', 'https://play.google.com/store/apps/details?id=com.ncbaclusapromac.eBAF', 0, '2014-08-27 15:11:46'),
(5, 'a49af996-7f4c-1032-a010-c067c39cc60b', 'M', 'extensionWorker',  'https://play.google.com/store/apps/details?id=pt.com.extensionWorker', 0, '2014-08-27 15:11:46'),
(6, 'a49afad6-7f4c-1032-a010-c067c39cc60b', 'W', 'promacAdministration', '  'http://ncbaclusapromac.com/clientLogin.html', 0, '2014-08-27 15:11:46');

DELIMITER $$
CREATE TRIGGER `applicationsUUID` BEFORE INSERT ON `applications`
FOR EACH ROW BEGIN
IF NEW.applicationID = '' THEN
SET NEW.applicationID = UUID();
END IF;
END
$$
DELIMITER ;

Gives:- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$

I know it is problem with the DELIMITER syntax but I can't see where.

Try:

CREATE TABLE `applications` (
   `id` int(2) NOT NULL,
   -- `applicationID` varchar(36) character set utf8 collate utf8_unicode_ci NOT NULL,
   `applicationID` varchar(39) character set utf8 collate utf8_unicode_ci NOT NULL,
   `applicationType` enum('M','W') character set utf8 collate utf8_unicode_ci NOT NULL,
   `applicationName` varchar(30) character set utf8 collate utf8_unicode_ci NOT NULL,
   `applicationPath` varchar(100) character set utf8 collate utf8_unicode_ci NOT NULL,
   `isDeleted` tinyint(1) NOT NULL default '0',
   `lastModified` timestamp NOT NULL default CURRENT_TIMESTAMP
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

INSERT INTO `applications` (`id`, `applicationID`, `applicationType`, `applicationName`,     `applicationPath`, `isDeleted`, `lastModified`)
VALUES
(1, 'a49af37e-7f4c-1032-a010-   c067c39cc60b', 'W', 'workshopWorkerWeb',   'http://www.workshopworker.com/workshopWorkerLogin/workshopWorkerLogin.html', 0, '2014-08-27   15:11:46'),
(2, 'a49af5c2-7f4c-1032-a010-c067c39cc60b', 'W', 'agriMapper', '', 0, '2014-08-27 15:11:46'),
(3, 'a49af702-7f4c-1032-a010-c067c39cc60b', 'M', 'promacRegistration',  'https://play.google.com/store/apps/details?id=com.ncbaclusapromac.ncbaclusapromac', 0, '2014-08-27 15:11:46'),
(4, 'a49af838-7f4c-1032-a010-c067c39cc60b', 'M', 'eBAF', 'https://play.google.com/store/apps/details?id=com.ncbaclusapromac.eBAF', 0, '2014-08-27 15:11:46'),
(5, 'a49af996-7f4c-1032-a010-c067c39cc60b', 'M', 'extensionWorker',  'https://play.google.com/store/apps/details?id=pt.com.extensionWorker', 0, '2014-08-27 15:11:46'),
-- (6, 'a49afad6-7f4c-1032-a010-c067c39cc60b', 'W', 'promacAdministration', '  'http://ncbaclusapromac.com/clientLogin.html', 0, '2014-08-27 15:11:46');
(6, 'a49afad6-7f4c-1032-a010-c067c39cc60b', 'W', 'promacAdministration', 'http://ncbaclusapromac.com/clientLogin.html', 0, '2014-08-27 15:11:46');

DELIMITER $$

CREATE TRIGGER `applicationsUUID` BEFORE INSERT ON `applications`
FOR EACH ROW
BEGIN
   IF NEW.applicationID = '' THEN
      SET NEW.applicationID = UUID();
   END IF;
END$$

DELIMITER ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM