触发器+事务+BCP

nice90 nice90 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
1、能够在触发器里将FOR INSERT,UPDATE ,DELETE 写到一起吗?
请看我的是否正确:
CREATE TRIGGER [Update_zxzxrefer_table]
ON [dbo].[zxzx_referback]
FOR INSERT, DELETE
AS
declare @zxid int
---for insert
-- transaction mytran1
select @zxid = 咨询id from inserted
if exists(select id from zxzx_refer where id=@zxid)
begin
update zxzx_refer set 状态=1 where id = @zxid
end

/* if @@error<>0
rollback
else
commit transaction mytran1 */
declare @zxid2 int
---for delete
--transaction mytran2

select @zxid2 = 咨询id from deleted
if exists(select id from zxzx_refer where id=@zxid2)
begin
delete zxzx_refer where id=@zxid2
end
/*
if @@error<>0
rollback
else
commit transaction mytran2 */

2、触发器里怎样将事务集成进去?
是在statement语句后面写rollback transaction吗?我的写法总是抱错。
3、BCP出来的文件,例如mytable表的bcp文件mytable_bcp.txt重新导入一张新表[newtable],同时要求mytable表的id(int 自增,PK)字段在导入的时候,每一条记录都加上5000,怎么写这个bcp语句?

谢谢各位兄弟姐妹!
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
nice90
疑难问题 22,298 成员 121,727 内容