select Name '姓名',Age '年龄',
(select LessonName + ',' from Lesson where StudentId=s1.Id FOR XML PATH('')) '课程名称'
from Student s1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------创建触发器(插入)
create trigger after_insert_trigger on Student
After insert as
begin
insert into lesson values('政治','7')
end
insert into Student values('孙八','16')
select * from Student
select * from Lesson
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------创建触发器(删除)
create trigger after_delete_trigger on Student
after delete as
begin
delete from lesson where studentId=2
end
delete from Student where Id=2
select * from Student
select * from Lesson