Irakli Lekishvili
Irakli Lekishvili

Reputation: 34198

sql server triggers

Hello I need help for creating trigger which would insert id into table1 when table2 filled with row

Upvotes: 0

Views: 166

Answers (4)

yorah
yorah

Reputation: 2673

When you define a trigger FOR INSERT, you have access to the inserted logical table. You can use it to retrieve the id of the inserted row, and store it in another table.

Something like:

CREATE TRIGGER trig
ON table2
FOR INSERT
AS
INSERT INTO table1 (id)
SELECT ins.id FROM inserted ins
GO

Upvotes: 0

nvogel
nvogel

Reputation: 25534

You don't need a trigger for that. Use a regular stored procedure.

Upvotes: 1

Sudantha
Sudantha

Reputation: 16224

Trigger should be created in the Table 2 insert

create trigger *< trigger_name >* on *< table_name >* for INSERT AS

//insert statement for table1

Upvotes: 1

m.edmondson
m.edmondson

Reputation: 30922

I suggest you start here

Upvotes: 1

Related Questions