日期:2014-05-16  浏览次数:20533 次

视图理解
create view TestView as
  select * from table_1...


select * from TestView

//多表视图更新----------------触发器instead of



create view TestView as
select student.id,student.name,student.sex,class.classname,class.classid from student left join class on student.classid=class.classid



create trigger triTestView
on testView
instead of insert
as
begin
if(not exists(select class.classid from class,inserted where class.classid=inserted.classid))
insert into class select inserted.classid,inserted.classname from inserted
if(not exists(select student.id from student,inserted where student.id=inserted.id))
insert into student select inserted.name,inserted.sex,inserted.id ,inserted.classid from inserted
else
update student set student.id=inserted.id,student.name=inserted.name from student,inserted where student.id=inserted.id
end