Verified Commit 30aa10f8 authored by Kiryuu Sakuya's avatar Kiryuu Sakuya 🎵
Browse files

Finish No.2

parent c0cfb3af
......@@ -304,14 +304,22 @@ DELIMITER ;
### 8. 用 SQL 编写一个完整性规则,当插入上映信息时,如果公司名称为 `Warner Bros` 并且该公司的电影的制作年份大于 2012,则自动将票价提高 20%
```mysql
DELIMITER //
CREATE TRIGGER oh_my_2012 AFTER INSERT ON I FOR EACH ROW
BEGIN
UPDATE I SET
Iprice = New.Iprice * 1.2
WHERE I.Mno IN (SELECT M.Mno FROM M WHERE M.Mname = 'Warner Bros' AND M.Myear = '2012');
END //
DELIMITER ;
```
不完整测试代码(懒得补充其它的了,电影是[疯狂原始人](https://movie.douban.com/subject/1907966/)):
```mysql
INSERT INTO I (
Ino, Mno, Itime, Iprice
) VALUE (
40004, 30004, "2013-04-20", "9.99"
);
```
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment