我正在尝试使用 MAMP 为 joomla2.5 应用程序创建一个 mysql 触发器。我的触发器:
CREATE TRIGGER `getDivision` BEFORE INSERT ON `encex_autoschedGames`
FOR EACH ROW BEGIN
select division into @div_a from encex_autoschedTeams where team_name = new.team_a;
set new.division = @div_a;
END
我不断收到以下错误:
Column 'division' cannot be null
故事:
我有两张桌子:1)游戏2)团队。Teams 有列“team_name”和“division” 游戏有列“team_a”、“team_b”和“division”
样品表:
Teams table:
Team_name, Division
"team1","A"
"Team2","A"
"Team3","A"
"Team4","A"
"Team5","B"
"Team6","B"
"Team7","B"
"Team8","B"
对于游戏表,我希望分区来自 Teams 表。因此,当我插入 Team1 Vs Team2 时,它会自动将分区填充为 A。
Games Table:
Team_a, Team_b, Division
"Team1", "Team2", "A"
我想创建一个触发器,这样当在游戏表中创建一行时,它会用'Teams'表中的'division'填充分区列,其中team_name = team_a。
理想情况下,我会构建它以确保 team_a 和 team_b 的划分相同,但我认为小步骤在这里最好。
经过一些调试,我相信我的错误在于: select Division into @div_a from encex_autoschedTeams where team_name = new.team_a;
出于某种原因,where 子句返回 null。经过一些命令行测试,它不应该是。也许 New.team_a 不对?