• Hi Henrik,

    actually you don't need it, but I agree it would be better practice for SQL Server 2005 as well as SQL Server 2008 to use the sys.databases view which is available from SQL Server 2005 and forward.

    Do do this while still maintaining the compatibility with SQL Server 2000, you could replace this:

    -- determines when tempdb was created (done at startup)

    DECLARE @starttime datetime

    SET @starttime = (SELECT crdate FROM sysdatabases WHERE name = 'tempdb' )

    With this:

    -- determines when tempdb was created (done at startup)

    DECLARE @starttime datetime

    DECLARE @sql_version sysname

    SET @sql_version = convert(sysname, (SELECT SERVERPROPERTY('Productversion')))

    IF (@sql_version NOT LIKE '8.%')

    BEGIN

    -- SQL Server 2005 and forward

    SET @starttime = (SELECT create_date FROM sys.databases WHERE name = 'tempdb')

    END

    ELSE

    BEGIN

    -- SQL Server 2000

    SET @starttime = (SELECT crdate FROM sysdatabases WHERE name = 'tempdb')

    END

    The premises for this however is that you don't execute it on versions older than SQL Server 2000, but I hope you don't have any of them running anyway 🙂

    Best regards

    Lars Søe Mikkelsen

    JN Data