Khi thực hiện lệnh nhập cầu thủ thứ 2 thì mình gặp lỗi:
insert into CauThu (so_ao, ID_doi, ten, tuoi)
value ('42','1', 'Dat Van Tay', '24');
Error Code: 1242. Subquery returns more than 1 row
Code:
create table if not exists DoiBong(
ID_doi int(11) NOT NULL UNIQUE,
ten_doi varchar(30) NOT NULL UNIQUE,
PRIMARY KEY (ID_doi)
);
create table if not exists CauThu(
so_ao int(11) NOT NULL,
ID_doi int(11) NOT NULL,
ten varchar(30) NOT NULL,
tuoi int(11) NOT NULL,
PRIMARY KEY (so_ao, ID_doi),
constraint fk_CauThu_DoiBong FOREIGN KEY (ID_doi) references DoiBong (ID_doi) on delete restrict on update cascade
);
DELIMITER $
CREATE TRIGGER cauthu_AFTER_INSERT
AFTER
INSERT
ON cauthu FOR EACH ROW
BEGIN
declare CauThu_count INT;
select
count(*) INTO CauThu_count
from
CauThu
where
ID_doi = NEW.ID_doi;
if CauThu_count > 30 then signal sqlstate '45000'
set
message_text = "Mot doi bong co toi da 30 cau thu!";
end if;
if (
SELECT
NEW.so_ao
from
CauThu
) not between 0
and 99 then signal sqlstate '46000'
set
message_text = "So ao cau thu phai o trong khoang tu 0 den 99!";
end if;
END$
DELIMITER ;