我正在使用此处https://dev.mysql.com/doc/index-other.html
中的示例MySQL数据库'world'以下是表格的说明:
mysql> desc city; desc country; desc countrylanguage;
+-------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+----------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | NULL | auto_increment |
| Name | char(35) | NO | | | |
| CountryCode | char(3) | NO | MUL | | |
| District | char(20) | NO | | | |
| Population | int(11) | NO | | 0 | |
+-------------+----------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
+----------------+---------------------------------------------------------------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------------------------------------------------------------------------------+------+-----+---------+-------+
| Code | char(3) | NO | PRI | | |
| Name | char(52) | NO | | | |
| Continent | enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') | NO | | Asia | |
| Region | char(26) | NO | | | |
| SurfaceArea | float(10,2) | NO | | 0.00 | |
| IndepYear | smallint(6) | YES | | NULL | |
| Population | int(11) | NO | | 0 | |
| LifeExpectancy | float(3,1) | YES | | NULL | |
| GNP | float(10,2) | YES | | NULL | |
| GNPOld | float(10,2) | YES | | NULL | |
| LocalName | char(45) | NO | | | |
| GovernmentForm | char(45) | NO | | | |
| HeadOfState | char(60) | YES | | NULL | |
| Capital | int(11) | YES | | NULL | |
| Code2 | char(2) | NO | | | |
+----------------+---------------------------------------------------------------------------------------+------+-----+---------+-------+
15 rows in set (0.00 sec)
+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| CountryCode | char(3) | NO | PRI | | |
| Language | char(30) | NO | PRI | | |
| IsOfficial | enum('T','F') | NO | | F | |
| Percentage | float(4,1) | NO | | 0.0 | |
+-------------+---------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
我正在尝试建立一个触发器,它只会在满足以下条件时从城市表中删除城市:
这是我现在的代码 -
DELIMITER $$
CREATE TRIGGER city_45_SDD
BEFORE DELETE ON city
FOR EACH ROW
BEGIN
DECLARE Lang varchar(25);
DECLARE Percent Float(4);
DECLARE Official varchar(1);
SELECT Language INTO Lang FROM countrylanguage;
SELECT Percentage INTO Percent FROM countrylanguage;
SELECT IsOfficial INTO Official FROM countrylanguage;
IF Lang <> 'English' AND Percent > 45 AND Official = 'T'
DELETE FROM city (ID, Name, CountryCode, District, Population);
END IF;
END$$
DELIMITER ;
不确定我做错了什么,所以如果有人能向我解释我做错了什么,那就太棒了。
抱歉,我忘了提及这些问题。