我有一个SQL问题,我做了一个我无法解决的触发器,我想为我的数据库做一个坏的过滤器。我做了这个触发器工作正常:
<a xlink:href="url-to-go-to">
现在我想这样做,以便从现有的表中选择坏词,从我的数据库中选择'Abusivewords'。此触发器已创建,但不会更改任何内容:
USE dbi353348
GO
Create TRIGGER trChangeAbusiveWordzondertable
ON Post
AFTER INSERT
AS
DECLARE @Posttekst varchar(300);
DECLARE @AccountID int;
DECLARE @PostID int;
SELECT @Posttekst=i.Post FROM inserted i;
SELECT @AccountID=i.Account_ID FROM inserted i;
SELECT @PostID=i.Post_ID FROM inserted i;
BEGIN
DECLARE @AbusiveWords TABLE(ID INT,Word VARCHAR(10))
INSERT INTO @AbusiveWords (ID,Word) values (1,'kanker'),(2,'tyfus'),(3,'tering'),(4,'kut'),(5,'lul'),(6,'eikel'),(7,'klootzak'),(8,'hoer'),(9,'flikker'),(10,'mongool'),(11,'slet'),(12,'bitch');
UPDATE @AbusiveWords
SET @Posttekst=REPLACE(@Posttekst,Word,REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(Word,'A','#'),'E','%'),'I','$'),'O','*'),'U','@'))
UPDATE Post
SET Post = @Posttekst
WHERE Post_ID = @PostID
END
我在更新声明中的某处确认错误。
答案 0 :(得分:0)
更新@Posttekst的问题应该是来自AbusiveWords的字段
UPDATE AbusiveWords
SET WORD=REPLACE(@Posttekst,Word,REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(Word,'A','#'),'E','%'),'I','$'),'O','*'),'U','@'))