我该如何编写触发器来查找重复值并将其删除。
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)