Tags: t-sql

Return Default SQL Server Folder

Below script will query registry settings to return folder informations (SQL Root, Data, Log and Backup). I use this script to determine the default locations, put it in variables an use it for creating databases or backups. more »

List all tables with specified field

DECLARE @COL_NAME NVARCHAR(50)SET @COL_NAME = '%SOMESTRING%'SELECT DB_NAME(DB_ID()) AS DatabaseName, B.name AS TableName, A.name AS ColumnNameFROM sys.syscolumns AS A INNER JOIN sys.sysobjects AS… more »

T-SQL Programmability Features in SQL Server 2008

Itzik Ben-Gan starts with a Whitepaper for SQL Server 2008 - An Introduction to New T-SQL Programmability Features in SQL Server 2008. Link: http://msdn.microsoft.com/en-gb/library/cc721270(SQL.100).aspx A must read! CUtosc more »

SQL Server Automation Scripts

The Microsoft SQL Server Community introduces a new OPSDB Section (SQL Server Automation Scripts), with T-SQL Scripts for administration and analysing the entire SQL Server. You can visit OpsDB Section here. CUtosc more »

Did you track the growth of your database-backup?

Frequently you'll want to know how fast your database-backup has been growing. Perhaps you have implement a SAN Backup-Device for Backup-to-disk, or you only want know how fast your database has been growing. This TSQL statement will query the [msdb]..[b… more »

SQLExamples: Common Solutions for T-SQL Problems

There is a new great WIKI ressource for common T-SQL solutions at MSDN Code Gallery, it's called SQLExampels. In this WIKI presented information, represents the suggestions, ideas, and opinions of Volunteer Moderators and Answerers (you know Arnie Roland… more »

Orphan SQL-Server accounts

By using SP_MSForEachDB you can detect and display orphan SQL-Server accounts from all the databases of your SQL-Server.EXEC SP_MSForEachDB 'USE [?]; -- SYSTEM DATABASE ARE EXCLUDED IF DB_ID(''?'') > 4 SELECT ''?'' as DBName, name… more »

Determine the last change of the sa password?

Let us face it, when did you last change the sa password? You can check last change in SQL Server 2005, for the sa login by using LOGINPROPERTY function. Execute the following T-SQL code: SELECT LOGINPROPERTY ('sa', 'PasswordLastSetTime') And a little… more »

Checking the running time since last SQL-Server instance startup

Below script will query sys.dm_exec_sessions to find out how long the SQL-Server instance is running.DECLARE @elapsed_time AS DATETIME, @lr_start_time AS DATETIMESELECT @lr_start_time = (SELECT last_request_start_time FROM sys.dm_exec_ses… more »