今天看一本数据库的书,要求写一个保证表间完整性的触发器(学生、课程、选课三个表),他给的答案是这样的:
create trigger sc_update on sc
for update
as if(select count(*)
from student,updated,course
where student.sno=updated.sno and course.cno=updated.cno)=0
rollback transaction
请问updated是什么表?
create trigger sc_update on sc
for update
as if(select count(*)
from student,updated,course
where student.sno=updated.sno and course.cno=updated.cno)=0
rollback transaction
请问updated是什么表?
解决方案 »
- 数据库备份还原问题
- 请问WEB数据库操作(SELECT,UPDATE,INSERT)是否有可能造成服务器死机?
- sql server 2005 中:由三张表中的数据得到一张表,该表的某列对应两个表达式怎么办
- 兄弟们来看看:ADO执行SQL语句,如果同时执行几条语句
- 如何在两张表之间复制相同字段?
- 请教下各位SQL的大大这个表里面的数据怎么填?
- 在搜索结果中如何将varchar型的字段聚合
- 高手请进-》关于 Select * from Table_Name where Field1 in (变量) 的问题??
- 关于创建外键的问题
- sql如何高效查询某节点下的所有叶子节点?
- 简单的查询!
- 请教名位查询语句:
这两天都看到你,你们星期不休息??
create table T(a int,b int)
insert into T select 1,1
go--创建触发器
create trigger trg_A
on T
for update
as
begin
if update(a)
update t1 set b=t1.b+1 from T t1 where exists(select 1 from inserted where b=t1.b)
if update(b)
update t1 set a=t1.a+1 from T t1 where exists(select 1 from inserted where a=t1.a)
end
go--执行触发操作
update T set b=b+2
select * from t
SQL Server 啊 努力 奋斗-----------------------------------------------------