Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Trigger

Author  Topic 

supersql
Yak Posting Veteran

99 Posts

Posted - 2005-09-20 : 13:28:21
Can I write a trigger that fires like..
when new rows(5) are inserted into a table,I want the IDENTITY values of this 5 rows to be inserted into its child table where it has the same column as FK.
If its possbile to write a trigger,can any one help how to do tht?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-09-20 : 13:43:19
[code]
create trigger trig_table1
as
insert into table2 (columns)
select columns
from table1 t1
join inserted i on t1.id = i.id
[/code]


Go with the flow & have fun! Else fight the flow
Go to Top of Page

supersql
Yak Posting Veteran

99 Posts

Posted - 2005-09-20 : 13:50:38
Here is my requirement
TableA (A1(PK),A2,A3)
TableB (B1(PK),A1(FK),B2,B3)
when 5 rows are inserted into TableA,I want to insert 5 A1 values into TableB(A1).
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-09-20 : 14:05:47
i gave you the conceptual solution.
now you just need to apply it to your problem.
or is there some other problem you're not telling us?

Go with the flow & have fun! Else fight the flow
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-09-20 : 14:27:18
CREATE TRIGGER itrg_Table1
ON Table1
FOR INSERT
AS
INSERT INTO Table2(A1)
SELECT A1
FROM inserted

GO

Tara
Go to Top of Page
   

- Advertisement -