获取SQL Server实例正常运行时间

在本文中,将介绍如何确定实例正常运行时间。

第1步

登录SSM并连接到数据库引擎。

第2步

打开新的查询窗口。

第3步

在新查询窗口中执行以下代码。

declare @startupDate datetime

declare @days boirnt

declare @hours boirnt

declare @minutes boirnt

declare @seconds boirnt

select  @startupDate = CrDate,

@seconds = DateDiff(second, CrDate, getdate()),

@days = @seconds/60/60/24,

@seconds = @seconds - (@days*60*60*24),

@hours = @seconds/60/60,

@seconds = @seconds - (@hours*60*60),

@minutes = @seconds/60,

@seconds = @seconds - (@minutes*60)

from    sysdatabases (nolock)

where   [name] = 'TempDb'

select  @startupDate startup_time,cast(@days as varchar) + ' days ' +

case when @hours < 10 then '0' else '' end + cast(@hours as varchar) + ':' +

case when @minutes < 10 then '0' else '' end + cast(@minutes as varchar) + ':' +

case when @seconds < 10 then '0' else '' end + cast(@seconds as varchar)

as online_duration
日期:2020-06-02 22:17:48 来源:oir作者:oir