Skip to content

Commit

Permalink
Merge pull request #28 from SBD1/#11-trigger/stored_procedure
Browse files Browse the repository at this point in the history
#11 trigger/stored procedure
  • Loading branch information
HeBatalha authored Dec 4, 2023
2 parents 48b517c + 9f83d3d commit ac0a7af
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion game/scripts/DDL/GeneralizacaoPersonagem.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,20 @@ CREATE OR REPLACE FUNCTION check_pc() RETURNS trigger AS -- Procedure para checa
CREATE TRIGGER check_pc -- Trigger para adicionar NPC
BEFORE UPDATE OR INSERT ON npc
FOR EACH ROW
EXECUTE PROCEDURE check_pc();
EXECUTE PROCEDURE check_pc();

CREATE OR REPLACE FUNCTION check_npc() RETURNS trigger AS -- Procedure para checar se o item adicionado ja pertence a npc
$check_npc$
BEGIN
PERFORM * FROM npc WHERE Personagem = NEW.Personagem;
IF FOUND THEN
RAISE EXCEPTION 'O Id ja pertence a npc';
END IF;
RETURN NEW;
END
$check_npc$ LANGUAGE plpgsql;

CREATE TRIGGER check_npc -- Trigger para adicionar PC
BEFORE UPDATE OR INSERT ON pc
FOR EACH ROW
EXECUTE PROCEDURE check_npc();

0 comments on commit ac0a7af

Please sign in to comment.