我有SQL trigger
,我想将其转换为MYSQL trigger
下面是我的SQL触发器的代码:
Create TRIGGER Trigger_INSERT_Student
on [Student]
AFTER INSERT
AS
BEGIN
declare @S_Id int;
declare @First_Name var char(255);
declare @Last_Name var char (255);
declare @Program var char (100) ;
declare @GPA float ;
declare @Birthday_date ;
declare @Blood_Group var char(255) ;
declare @Contact_Number var char (10);
declare @Address var char(255) ;
declare @City var char (255) ;
declare @Trigger_Action var char (255) ;
select @S_Id=S_Id from inserted ;
select @First_Name=First_Name from inserted ;
select @Last Name=Last_Name from inserted ;
select @Program=Program from inserted ;
select @GPA=GPA from inserted ;
select @Birthday=Birthday from inserted ;
select @Blood_Group=Blood_Group from inserted ;
select @Contact Number=Contact_Number from inserted ;
select @Address= Address from inserted ;
select @City= City from inserted ;
set @Trigger Action= 'Record Inserted';
INSERT INTO Student History
(S_Id,First_Name,Last_Name,Program,GPA,Birthday,Blood_Group,Contact_Number,Address,City,Trigger-Action)
VALUES (@S_Id,@First-Name,@Last-Name,@Program,@GPA,@Birthday,@Blood_Group,@Contact_`enter code here`Number,@Address,@City,@Trigger Action)
END
任何人都可以帮助我在MYSQL触发器中转换此触发器。欢迎任何建议
答案 0 :(得分:0)
you can try like this in MySQL:
DELIMITER $$
DROP TRIGGER IF EXISTS trigger_insert_student $$
CREATE TRIGGER trigger_insert_student AFTER
INSERT ON [Student]
FOR EACH ROW BEGIN
INSERT
IGNORE INTO student history (s_id, first_name, last_name, program, gpa, birthday, blood_group, contact_number, address, city, TRIGGER-action)
VALUES (NEW.s_id,
NEW.first_name,
NEW.last_name,
NEW.program,
NEW.gpa,
NEW.birthday,
NEW.blood_group,
NEW.contact_number,NEW.address,NEW.city,'Record Inserted') END $$
DELIMITER ;
DELIMITER $$