【发布时间】:2014-10-16 09:02:32
【问题描述】:
为了简单起见,假设我有两张桌子
user table (id, email)
user log table (id, date)
无论 id 被插入到 user 表中,相同的 id 应该被插入到 user_log 表中,否则事务应该失败。
我该怎么做
BEGIN TRANSACTION
INSERT into user(id, email) OUTPUT Inserted.id (1, 'a@x.com', 'x'), (2, 'b@x.com', 'y')
// I also want to be able to do
INSERT into user_log(id, date) values(1, date), (2, date)
COMMIT TRANSACTION
【问题讨论】:
-
这可能是实现触发器的理想选择。你考虑过这种方法吗?
标签: sql-server sqltransaction multiple-insert