gpt4 book ai didi

mysql - 在 mysql 5.0.77 中定义触发器的语法错误

转载 作者:行者123 更新时间:2023-11-29 23:50:44 26 4
gpt4 key购买 nike

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;

-- -- 转储表应用程序的数据 --

 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 ;

给出:- 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'DELIMITER $$

附近使用的正确语法

我知道这是 DELIMITER 语法的问题,但我看不出问题出在哪里。

最佳答案

尝试:

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 ;

关于mysql - 在 mysql 5.0.77 中定义触发器的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25671372/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com