我正在尝试在 mySQL 中设置触发器,以便在添加、删除或更新新团队时触发 countTeams 中的更新,并将基本计数和 countNA 等更改为团队的相应国籍。
这是我的桌子:
CREATE TABLE countTeams(
base integer PRIMARY KEY,
countNA integer,
countEU integer,
countCN integer,
countSEA integer,
countINT integer,
countCIS integer
);
CREATE TABLE Team(
TeamName varchar (30) PRIMARY KEY,
Captain varchar (30),
Nationality varchar (5) NOT NULL,
CreationDate date,
Description varchar (50),
foreign key(Captain) references Emails(Username)
);
我失败的触发尝试。
CREATE TRIGGER teamsDown
AFTER INSERT ON Team FOR EACH ROW
UPDATE countTeams
BEGIN
SET base = (base - 1)
IF Team.Nationality= "NA" THEN
UPDATE countTeams
SET countNA = (countNA - 1)
ELSEIF Team.Nationality = "EU" THEN
UPDATE countTeams
SET countEU = (countEU - 1)
IF Team.Nationality = "CN" THEN
UPDATE countTeams
SET countCN = (countCN - 1)
IF Team.Nationality = "SEA"
UPDATE countTeams
SET countSEA = (countSEA - 1)
IF Team.Nationality = "INT"
UPDATE countTeams
SET countINT = (countINT - 1)
IF Team.Nationality = "CIS"
UPDATE countTeams
SET countCIS = (countCIS - 1)
END;