Reputation: 34198
Hello I need help for creating trigger which would insert id into table1 when table2 filled with row
Upvotes: 0
Views: 166
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
Reputation: 25534
You don't need a trigger for that. Use a regular stored procedure.
Upvotes: 1
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