gpt4 book ai didi

MySQL触发器将第一个表的数据插入后插入第二个表

转载 作者:行者123 更新时间:2023-11-29 23:25:44 24 4
gpt4 key购买 nike

Here are my tables.Student Table+++++++++++++++++++++++++++++++++++++++++++++++++++| s_id |    name     |   lname    | fname    | c_id |+++++++++++++++++++++++++++++++++++++++++++++++++++|  1   |     ali     |   ahmadi   | ahmad    |  1   ||  2   |  Hussain    |   Sharan   | Skekib   |  2   ||  3   |  Mahmood    | Shekibayee | Jahangir |  1   |+++++++++++++++++++++++++++++++++++++++++++++++++++Student_course Table+++++++++++++++++++++++| sc_id | s_id | c_id  |++++++++++++++++++++++|  1    |  1   |   1   ||  2    |  2   |   1   ||  3    |  3   |   2   |++++++++++++++++++++++Now I want to have a trigger that:When I insert new student into `student` table it should insert `s_id` and `c_id` into student_Coursetable.I am quite new to PHP and MySQL; any help will be highly appreciated.Thanks in advance.

最佳答案

假设 sc_idStudent_course 上自动递增的主键,这可能相当简单

delimiter //
create trigger ins_student_course after insert on Student
for each row
begin
insert into Student_course (s_id,c_id) values (new.s_id,new.c_id);
end ;//

delimiter ;

关于MySQL触发器将第一个表的数据插入后插入第二个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26988531/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com