create tigger f on tb for insert,update as begin if update tb(u) update tb set e=u+v end
姐姐 如果用if update() 那添加時候這個觸發器就不起作用了
---使用计算列 create table tb(u datetime,v int,e as dateadd(dd,v,u)) go insert into tb(u,v) select '2010-04-03',3 go select * from tb go--结果: u v e ----------------------- ----------- ----------------------- 2010-04-03 00:00:00.000 3 2010-04-06 00:00:00.000
在公式裏輸入 (dateadd(day,[v],[u]))
create table tb ( V int, E datetime, U datetime ) create trigger f on tb for insert,update as begin if update(U) update tb set e=u+v endINSERT TB (V,E,U) SELECT 5,'2010-03-05','2010-04-05'
if update tb(u) update tb set e=u+v我想问下这样写会不会把整个表都更新一下,还是只更新这条记录?
for insert,update
as
begin
if update tb(u)
update tb set e=u+v
end
如果用if update()
那添加時候這個觸發器就不起作用了
---使用计算列
create table tb(u datetime,v int,e as dateadd(dd,v,u))
go
insert into tb(u,v) select '2010-04-03',3
go
select * from tb
go--结果:
u v e
----------------------- ----------- -----------------------
2010-04-03 00:00:00.000 3 2010-04-06 00:00:00.000
(dateadd(day,[v],[u]))
V int,
E datetime,
U datetime
) create trigger f on tb
for insert,update
as
begin
if update(U)
update tb set e=u+v
endINSERT TB (V,E,U)
SELECT 5,'2010-03-05','2010-04-05'
update tb set e=u+v我想问下这样写会不会把整个表都更新一下,还是只更新这条记录?
这样设置的话,在设计器里这个字段好像就没有数据类型了。用ASP.NET 读取的时候按datetime来取会不会出错?
on table1
for insert,update
as
begin
if update(U)
update table1 set E=dateadd(dd,V,U)
where ...end
create tigger t_ri on tb for update,insert
as
begin
update tb set e=u+v
end
from inserted i ,table1 t
where i.id=t.id