I have 3 tables that are called:
- character_
- learned_skills
- skills
"character_" contains certain informations on a list of characters, while the table "skills" contrains a list of skills. the 3rd table is the list of the skills each character has learned.
However I want to able ones a character has been deleted from the character_ table, it also deletes the name of that character and the skills it has learned from the table "learned_skills".
I assume that a trigger is required in this situation. I know that the syntax is:
CREATE TRIGGER trigger_name trigger_time trigger_event ON tbl_name FOR REACH ROW tigger_statement;
However I can't figure out how the trigger_statement should look like.
CREATE TRIGGER delete_char_ AFTER DELETE ON character_ FOR REACH ROW trigger_statement
Is it enough with a sigle statement or does it require several statements and or cascade?
What would you do in this situation?
CREATE TABLE character_ (
Name_ varchar (30) NOT NULL,
Class varchar (30),
World_Type varchar (15),
Str integer ,
WS integer ,
BS integer ,
Fel integer ,
Per integer ,
Int_ integer ,
Agi integer ,
WP integer ,
Tough integer ,
PRIMARY KEY (Name_) ,
FOREIGN KEY (Class) REFERENCES Class(Class_name),
FOREIGN KEY (World_Type) REFERENCES World_Type(Name_) );
CREATE TABLE Skills (
SkillName varchar (30) NOT NULL,
Type_ varchar (30),
Characteristic varchar (30),
Descriptor varchar (30),
PRIMARY KEY (SkillName) );
CREATE TABLE Learned_Skills (
Character_Name varchar (30) NOT NULL,
Skill_Name varchar (40) NOT NULL,
PRIMARY KEY (Character_Name,Skill_Name),
FOREIGN KEY (Character_Name) REFERENCES character_(Name_),
FOREIGN KEY (Skill_Name) REFERENCES Talents(TalentName) );
UPDATE:
So I have had help to understand and make a DELETE trigger, but I have found out that need to create a multiple trigger on two tables, I know that its not possible to create a trigger on two with the same triggertime and event, but is there a way around it? What I need is the following:
DELIMITER //
CREATE TRIGGER delete_char_ AFTER DELETE ON character_
FOR EACH ROW begin
DELETE FROM learned_skills
WHERE learned_skills.Character_Name = old.Name_;
DELETE FROM learned_talents
WHERE learned_talents.Character_Name = old.Name_;
END;
//
DELIMITER ;
When I run this code I get error code:
1235, this version of mysql doesn't yet support 'multiple triggers with the samme action time and event for one table