我知道我应该首先阅读如何进入mysql语法,但我的时间很短。所以我想在这里寻求帮助。
这是来自sql-server的触发器,我需要将其转移到mysql中。我做了几行改变但现在卡住了。
if语句有一个语法错误。 “意外的'IF'”(试过的情况......但也有错误) 最后在Alter- table-命令之前的另一个。 “此时GO不是有效的输入”
CREATE TRIGGER
TEST_TRIGGER
AFTER insert
ON
TEST_TABLE
For each row
BEGIN
SET v_ANZAHL = (select COUNT(1) from inserted),
IF v_ANZAHL = 1 then
DELETE FROM
filter_group
WHERE
filter_groups_id IN
(select FilterID from filter_groups_view);
INSERT INTO filter_group
(filter_groups_id
,group_id)
SELECT
FilterID,
GruppeID
FROM
filter_groups_view
END
GO
ALTER TABLE TEST_TABLE ENABLE TRIGGER TEST_TRIGGER
GO
答案 0 :(得分:0)
有多个错误:
以下是更正的代码,但由于缺少表格和内容而未经测试:
DELIMITER $$
CREATE TRIGGER
TEST_TRIGGER
AFTER insert
ON
TEST_TABLE
For each row
BEGIN
SET v_ANZAHL = (select COUNT(1) from inserted);
IF v_ANZAHL = 1 then
DELETE FROM
filter_group
WHERE
filter_groups_id IN
(select FilterID from filter_groups_view);
INSERT INTO filter_group
(filter_groups_id
,group_id)
SELECT
FilterID,
GruppeID
FROM
filter_groups_view;
END IF;
END $$
DELIMITER ;