A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @NachitoMax
The key point of this issue is how you can get the inserted values and use them later.
Therefore, we need to introduce two special tables: inserted & deleted.
Naturally, inserted will contain rows only for INSERT and UPDATE triggers, and it will be empty for DELETE triggers. Similarly, deleted will contain rows only for DELETE and UPDATE triggers, and it will be empty for INSERT triggers.
So the code maybe like:
CREATE TRIGGER Trigger_Test ON MyTable
FOR /*You can use either the keyword FOR or the keyword AFTER to define an AFTER trigger*/
INSERT AS
INSERT INTO AnotherTable (column1,column2,...) SELECT column1,column2,... FROM inserted
For more details about CREATE TRIGGER, please refer to this document: CREATE TRIGGER (Transact-SQL)
For some examples about TRIGGER AFTER INSERT, please refer to this article: SQL Server trigger after insert with examples
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.