http://wenku.baidu.com/view/0f08e657ff00bed5b8f31d25.html
我另外给你一段代码,给你参考:
create table organization(
o_no int not null auto_increment,
o_name varchar(32) default '',
primary key (o_no)
) engine=innodb
create table member(
m_no int not null auto_increment,
m_name varchar(32) default '',
o_no int,
primary key (m_no),
constraint organization_member_fk foreign key (o_no) references organization(o_no)
) engine=innodb
insert into organization(o_no, o_name) values
(null, 'o1'),
(null, 'o2')
insert into member(m_no,m_name,o_no) values
(null, 'm1',1),
(null, 'm2',1),
(null, 'm3',1),
(null, 'm4',2),
(null, 'm5',2)
delimiter $$
create trigger organization_delete_before_trigger before delete on organization for each row
begin
delete from member where o_no=old.o_no
end
$$
delimiter
select * from member
delete from organization where o_no=1
select * from member
可以这样:
select count(*)from t_lesson
where t_lesson.bookId in (
select id
from t_book
where t_book.userId=2)
望采纳,谢谢
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)