用CASECASE WHEN ID=1 THEN ... WHEN ID=0 THEN ... END
1、在时间字段上加个默认值 getdate() 2、update触发器 create trigger tru_A on A for update as begin update A set 时间=getdate() from A , inserted i ,deleted d where A.主键=i.主键 and A.主键=d.主键 and i.id<>d.id end
当ID=1时 表示电脑开始运行,并记录运行时间。 当ID=0时 表示电脑关机,并记录关机时间==>怎么个记录法子 怎么样编写这个算法,有没有什么算法可以直接检测到 ID值的变化并记录时间? ==》 检测到是可以写个触发器 把时间 参数记录到一个表里 之后查询该表就可以了 ..create trigger trup on tbName after update as begin if update(ID) insert 检测表 --这个表预先建立好 select id ,getdate() from inserted end 大概就这么些~
WHEN ID=0 THEN ...
END
2、update触发器
create trigger tru_A on A for update
as
begin
update A set 时间=getdate() from A , inserted i ,deleted d
where A.主键=i.主键 and A.主键=d.主键 and i.id<>d.id
end
当ID=0时 表示电脑关机,并记录关机时间==>怎么个记录法子
怎么样编写这个算法,有没有什么算法可以直接检测到 ID值的变化并记录时间?
==》
检测到是可以写个触发器 把时间 参数记录到一个表里
之后查询该表就可以了 ..create trigger trup on tbName
after update
as
begin
if update(ID)
insert 检测表 --这个表预先建立好
select id ,getdate()
from inserted
end
大概就这么些~
A B C D
ID列 运行状态列 开机时间列 关机时间列