小编fas*_*ast的帖子

插入后如何查找重复值并删除它们(使用触发器)?

我该如何编写触发器来查找重复值并将其删除。

CREATE TRIGGER [dbo].[deleteduplicate] 
ON [dbo].[products]
AFTER INSERT
AS
BEGIN
    declare @productname nvarchar(20),@prodcutid int
    select productname=@productname,productid=@prodcutid from inserted
    if exists (select productname=@productname from products)
    begin
        delete products
        where @productname=productname
    end

END
Run Code Online (Sandbox Code Playgroud)

sql sql-server triggers duplicates sql-delete

0
推荐指数
1
解决办法
40
查看次数

标签 统计

duplicates ×1

sql ×1

sql-delete ×1

sql-server ×1

triggers ×1