0
create table t1(col int);
create table t2(col int);
CREATE TRIGGER tr
ON t1
AFTER INSERT
as
begin
INSERT INTO t2(col) values(1)
end;
-- tables and trigger created
INSERT INTO t1(col) values(1), (2)
當我運行此插入查詢時,在表t2
中插入事件只發生一次。如何在SQL Server中爲每行創建觸發器
需要FOR EACH ROW
聲明在觸發器中,但如何使這在SQL Server?沒有在文檔中找到,並在谷歌搜索後,也沒有找到一些好的解決方案。
SQL Server不支持行級觸發 –
如果你真的需要它們,你必須使用遊標:http://stackoverflow.com/questions/5805413/how-can-i-get-a-trigger-to-fire-on-each-inserted-行d uring-an-insert-into-table –
@a_horse_with_no_name:親愛的使用INSERTED表,你可以逐行工作。或者我不明白這個問題? –