码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2019-05-31 19:25:21      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:bsp   insert   pre   delete   class   esc   数据   down   order   

--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

 

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

标签:bsp   insert   pre   delete   class   esc   数据   down   order   

原文地址:https://www.cnblogs.com/RainHouse/p/10956925.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!