Reputation: 989
I have two tables with 1 to many relationship. Here are they:
When inserting into ActivityAttribute
I would like to use generated idAA
for inserting many records to PersonActivityAttribute
- one for each existing value of PersonActivityAttribute.idPA. It goes like this: when I insert a new record to ActivityAttribute
with idAA = 5
I want the following result
The question is - how can I achive it using trigger? Is it possible?
Upvotes: 1
Views: 63
Reputation: 2774
You can make use of the below query
CREATE TRIGGER trgAfterInsert on ActivityAttribute
FOR INSERT
AS DECLARE @idAA INT;
SELECT @idAA=i.idAA FROM inserted i;
INSERT INTO PersonActivityAttribute(idPA,idAA,value)
SELECT DISTINCT idPA, @idAA, NULL value
FROM PersonActivityAttribute;
Hope this should help you out.
Upvotes: 1