是否可以在数据库中保留正在运行的计时器

本文关键字:运行 计时器 保留 数据库 是否 | 更新日期: 2023-09-27 17:56:14

是否可以在数据库中保留正在运行的计时器?

例如。假设我创建了一个计时器实体,该实体能够保存正在运行的计时器的单个记录?

据我所知,存储在数据库中的东西必须是静态的。那么有没有办法在数据库中保留非静态记录呢?

是否可以在数据库中保留正在运行的计时器

.NET 中的秒表类所做的只是写下启动秒表的时间,然后在查看结果时,它只是从停止/当前时间中减去开始时间。

它会像

create table Stopwatches
(
    Id int identity(1,1) primary key clustered,
    StartTime DateTime not null,
    EndTime DateTime null
)

启动秒表

insert into Stopwatches (StartTime) values (GetDate())
select @@IDENTITY as StopwatchId; 

停止秒表

update Stopwatches
set EndTime = GetDate()
where id = @stopwatchId

查看已用时间

select DateDiff(second, StartTime, EndTime) as Elapsed where id = @stopwatchId

使用虚拟表

试试这个

http://sqlite.org/lang_createvtab.html

它解释了他们对虚拟表的看法,但我认为你不能在数据库中做非静态