简体   繁体   English

SQL:在字符串上触发 Substring?

[英]SQL: Trigger Substring on string?

I've got a table in SQL with badwords and his ids, and also I've got a table with properties of photos of a gallery.我在 SQL 有一张桌子,上面有坏词和他的 ID,还有一张桌子,上面有画廊照片的属性。 I want to make a trigger that dont let you insert a photo with bad words on the photo.title and on the photo.description.我想制作一个触发器,不允许您在 photo.title 和 photo.description 上插入带有坏词的照片。 How can I do it??我该怎么做??

CREATE TABLE Photos ( photoId INT NOT NULL PRIMARY KEY AUTO_INCREMENT, title VARCHAR(128) NOT NULL, description VARCHAR(512), date DATETIME DEFAULT CURRENT_TIMESTAMP, url VARCHAR(512) NOT NULL, visibility VARCHAR(16) NOT NULL, userId INT, FOREIGN KEY (userId) REFERENCES users(userId), CONSTRAINT ValidVisibility CHECK (visibility in ('Public', 'Private')) ); 
CREATE TABLE BadWords ( wordId INT NOT NULL PRIMARY KEY AUTO_INCREMENT, word VARCHAR(100) NOT NULL );

EDIT: make a trigger on insertion that will do this select:编辑:在插入时触发将执行此操作 select:

 SELECT * FROM Photos, BadWords 
  
 WHERE  Photos.title LIKE CONCAT('%', BadWords.word ,'%') OR

        Photos.description LIKE CONCAT('%', BadWords.word ,'%')

and delete all results.并删除所有结果。 (the select is checking if title or description contains a value from the BadWords.word column ) (select 正在检查 title 或 description 是否包含 BadWords.word 列中的值)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM