T-SQL Stored Procedure to Report the Last Uptime of an Instance


/*
Stored proc to report uptime of a sql server instance based on the initialization time of its tempdb.

Version 2000+
*/

use master
go

IF EXISTS (SELECT * FROM sysobjects
WHERE name = 'sp__uptime'
AND type = 'P')
DROP PROC sp__uptime

go

create proc sp__uptime
AS
begin
select @@SERVERNAME as ServerName, crdate as LastUpTime
from master..sysdatabases where dbid = db_id('tempdb')
end
go

GRANT EXECUTE ON sp__uptime TO public
go

--Usage
exec sp__uptime
go

Advertisements

About Nick Xu

Not a DBA anymore
This entry was posted in T-SQL Script and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s