[英]SQL Server trigger insert values from new row into another table with many-to-many relationship
I have three tables: 我有三个表:
with many-to-many relationship 有多对多关系
what the insert trigger on tbl_options
I have to use to add the new options to each profile on tbl_profiles
, by default value of isChoose
is 0
我必须使用
tbl_options
上的插入触发器将新选项添加到tbl_profiles
上的每个配置文件的情况,默认情况下isChoose
值为0
and on the opposite side when insert a new profile binding it with all options on tbl_options
在另一侧,当插入新配置文件并将其与
tbl_options
上的所有选项tbl_options
In other words : 换一种说法 :
If I add new Option (4....E) to tbl_option
, the trigger must be insert two new rows on tbl_profileOption
: 如果我向
tbl_option
添加新的Option(4 .... E),则触发器必须在tbl_profileOption
上插入两个新行:
1....4.......0
2....4.......0
I hope that my question is clear, 我希望我的问题很清楚,
thank for all who try to help me... I got the solution 感谢所有尝试帮助我的人...我找到了解决方案
first trigger on tbl_option
第一次触发
tbl_option
go Create TRIGGER insertProfileToOption ON dbo.tbl_options AFTER INSERT AS insert into tbl_profileOption (profileOption_profileId, profileOption_optoinId) (select tbl_profiles.profile_id, @@IDENTITY from tbl_profiles)
second trigger on tbl_profile
tbl_profile
第二个触发器
go Create TRIGGER insertOptionToProfile ON dbo.tbl_profiles AFTER INSERT AS insert into tbl_profileOption (profileOption_profileId, profileOption_optoinId) (select @@IDENTITY, tbl_options.option_id from tbl_options)
if there is another solution this will be good, thank you 如果有其他解决方案,那将是很好,谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.