0

I'm working on a database, but when I use the statement

Insert into Personaggio (Nome, Storia, Personalità, StatisticheATK,StatisticheDEF, Salute,Denaro,NomeNEmico, NomeOggetto, NomeArma,NomeChip) values ("A2","A2 è un androide creato con lo scopo di attaccare le linee nemiche delle biomacchine.Tuttavia, essa si ribella alla YoHRa dopo alcuni fatti, e vive come una disertrice. ","All'inizio è taciturna e misteriosa, ma durante la storia si scopre essere abbastanza aggressiva e fumantina. Nutre profondo astio verso le biomacchine, tuttavia nel corso della storia si ricrederà . ",1200,500,2000,30000,NULL,NULL,NULL,NULL);

The log console gives me the error 1242: Subquery returns more than 1 row. It's clearly not a subquery, so what I am supposed to do? The triggers on the tables are 4, 2 on before insert and 2 on before update and they are basically the same, here's an example:

CREATE DEFINER = CURRENT_USER TRIGGER NierAutomata.Personaggio_BEFORE_INSERT_1 BEFORE INSERT ON Personaggio FOR EACH ROW BEGIN declare msg VARCHAR(150); if (999999 < (select Personaggio.Salute from Personaggio)) then set msg=concat('La salute massima non può superare il valore di 999.999'); signal sqlstate '45000' set message_text=msg; end if; END

I've already inserted 2 records on this table, but only this one is giving me trouble. My version is 8.0.23 build 365764. Any help?

I've already inserted 2 records on this table, but only this one is giving me trouble. My version is 8.0.23 build 365764.

Duz
  • 17
  • 2
  • That trigger prevents more that 2 rows in the Personaggio table. Re-write! – jarlh Feb 19 '21 at 14:51
  • Just use a check constraint instead of a trigger. – Shadow Feb 19 '21 at 15:18
  • @jarlh how do I tell the trigger to affect only one row then? – Duz Feb 19 '21 at 15:38
  • If the `(select Personaggio.Salute from Personaggio)` returns more than 1 row, the trigger will raise an error. I don't know what you're trying to do, so I can't give you the solution. – jarlh Feb 19 '21 at 15:44
  • @jarlh basically I'm trying to implement a trigger that block the user from putting a value too high in the record Personaggio.Salute. So, the if statement is supposed to check this new value of Personaggio.Salute, but I dont know how to solve it. – Duz Feb 19 '21 at 15:47
  • As Shadow already has pointed out, why not use a basic check constraint instead? – jarlh Feb 19 '21 at 15:49
  • @jarlh beacuse I need at least a few triggers for my project, and that's the only one that I came up with. – Duz Feb 19 '21 at 15:53
  • Then no need for select at all, just use NEW.fieldname to access the values to be inserted. – Shadow Feb 19 '21 at 16:50

0 Answers0