SQL Server触发将新行中的值插入到具有多对多关系的另一个表中 [英] SQL Server trigger insert values from new row into another table with many-to-many relationship
问题描述
我有三个表:
- tbl_profiles
- tbl_options
- tbl_profileOption
具有多对多关系
tbl_options
上的插入触发器是什么,我需要用来将新选项添加到tbl_profiles
上的每个配置文件,默认情况下,isChoose
的值为0
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
and on the opposite side when insert a new profile binding it with all options on tbl_options
换句话说:
如果我向tbl_option
添加新的Option(4 .... E),则触发器必须在tbl_profileOption
上插入两个新行:
If I add new Option (4....E) to tbl_option
, the trigger must be insert two new rows on 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
-
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)
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
这篇关于SQL Server触发将新行中的值插入到具有多对多关系的另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!