+----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| attractionID | varchar(30) | NO | PRI | NULL | |
| attractionName | char(30) | YES | | NULL | |
| description | char(100) | YES | | NULL | |
| ticketprice | int(11) | NO | | NULL | |
+----------------+-------------+------+-----+---------+-------+
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| packageNo | varchar(30) | NO | PRI | NULL | |
| attractionID | varchar(30) | NO | PRI | NULL | |
| numTickets | int(11) | NO | | NULL | |
+--------------+-------------+------+-----+---------+-------+
+---------------+-------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+------------+-------+
| packageNo | varchar(30) | NO | PRI | NULL | |
| passportNo | varchar(30) | NO | MUL | NULL | |
| fromDate | date | NO | | 0000-00-00 | |
| toDate | date | NO | | 0000-00-00 | |
| estimatedCost | int(11) | NO | | NULL | |
+---------------+-------------+------+-----+------------+-------+
delimiter //
create trigger estimatedCost_bi
after insert on ticketBooking
for each row
begin
set @package1=(select(sum(ticketprice*numTickets)
from attraction join ticketBooking using(attractionID)
join package using(packageNo)
where package.packageNo=new.packageNo);
update package join ticketBooking using(packageNo)
set estimatedCost = @package1
where ticketBooking.packageNo=new.packageNo;
end//
delimiter ;
答案 0 :(得分:0)
将来发布问题时,包含错误消息确实很有帮助。在这里。
错误1064(42000):您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在'from attraction join ticketBooking using(attractionID)附近使用正确的语法
这里的基本语法错误就在'from attraction'之前,我们找到了
set @package1=(select(sum(ticketprice*numTickets)
这里的问题是SELECT()是无效的语法。正确的语法是SELECT后跟一个空格。这似乎是一个额外的无与伦比的支架,所以您可以像这样删除它:
delimiter //
create trigger estimatedCost_bi
after insert on ticketBooking
for each row
begin
set @package1=(select sum(ticketprice*numTickets)
from attraction join ticketBooking using(attractionID)
join package using(packageNo)
where package.packageNo=new.packageNo);
使用(packageNo)更新包加入ticketBooking
设置estimatedCost = @ package1
其中ticketBooking.packageNo = new.packageNo; 结束// 分隔符;