Archive for the ‘SQL Scripts’ Category

LS Recover All Databases Query

Saturday, February 6th, 2010

-- This script will generate a
-- script to recover all log
-- shipped databases that are
-- in a 'RESTORING' state.
SELECT 'RESTORE DATABASE [' + name + '] WITH RECOVERY'
FROM   master.dbo.sysdatabases
WHERE DATABASEPROPERTYEX(name, 'Status') = 'RESTORING'
ORDER BY name
GO

SQL Version, SP Level and Edition Query

Friday, January 22nd, 2010

-- This query shows the SQL Server
-- version, SP Level and Edition.
SELECT SERVERPROPERTY('productversion') [Version],
SERVERPROPERTY ('productlevel') [SP Level],
SERVERPROPERTY ('edition') [Edition]
GO

SQL Connections by Database

Thursday, September 17th, 2009

-- This query will show current connections
-- and what database they're using.
SELECT  DB_NAME(dbid) AS [DatabaseName],
loginame as [User ID],
COUNT(dbid) AS [Connections]
FROM    sys.sysprocesses
WHERE   dbid > 0
GROUP BY db_id, loginname
GO