SQL 触发器 新建时删除相同数据

2019/05/31 18:42
阅读数 19
--create
alter trigger [dbo].[trigger_sqsj] 
on [dbo].[lctnrcrd] 
after INSERT as
BEGIN
declare @id char(50)
 select @id = (select top 1 id from [lctnrcrd] order by CONVERT(char(16),dlr,120) desc) 
 print @id 
 delete from [lctnrcrd] 
 --select * from [lctnrcrd] 
 where id = @id and 
 idowner+CONVERT(char(16),dlr,120) in 
(select idowner+CONVERT(char(16),dlr,120) from [lctnrcrd] where id not in(@id)) 
--select * from [lctnrcrd] order by CONVERT(char(16),dlr,120) desc
END
--select * from [lctnrcrd] order by CONVERT(char(16),dlr,120) desc

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部
返回顶部
顶部