Category Archives: SQL

T-SQL – Find Number of Rows of Database(s) tables Using Undocumented Procedure – sp_MSforeachdb and sp_MSforeachtable

On Technet forum, Op was looking for a way to get table cardinality for all databases in an instance.  There are many ways to get the result. This post gives you an idea and SQL in which undocumented SP’s being called  “sp_MSforeachdb and … Continue reading

Posted in sp_MSforeachtable, SQL, T-SQL | Tagged , , , , , , , , , , | 1 Comment

SQL – Split delimited columns using XML Or UDF function

The requirement is to convert the delimited column into rows Input data and required output details are given below Eno Ename Esloc EDept 1 ABC NJ 10,20,30,40,50 Output:- Eno Ename Esloc EDept 1 ABC NJ 10 1 ABC NJ 20 … Continue reading

Posted in SQL, T-SQL | Tagged , , , , , | Leave a comment

T-SQL – How to Find Number of Words in a Given String

TSQL: To find number of words in a given string Download the code https://gallery.technet.microsoft.com/T-SQL-How-to-Find-Number-533b6b39 DECLARE @DemoTable Table (Col varchar(500)); INSERT INTO @DemoTable (Col)VALUES (‘JOHN M SMITH ABC COMPANY’) SELECT col, len(Col) – len(replace(col, ‘ ‘, ”)) + 1 No_Of_Words from @DemoTable … Continue reading

Posted in SQL | 4 Comments

Capturing Database(s) and Table Usage stats – sp_spaceused simulation using DMVs

For more Information refer Technet Article Introduction sp_spaceused is one of the system stored procedure used frequently by many DBA’s that reveals amount of space used by database/tables. This procedure can be executed either by passing parameters or no parameters. The … Continue reading

Posted in SQL | Tagged , | Leave a comment

Capturing DB Usage stats – sp_spaceused simulation using DMV’s.

SP_SPACEUSED sp_spaceused is one of the system stored procedure used frequently by many dba’s that reveals amount of space used by database/tables. This procedure can be executed either by passing parameters or no parameters. The objective of this stored proc … Continue reading

Posted in SQL | Tagged , , | 2 Comments

Determine size of the file using T-SQL/Powershell/Ole Objects

There are many ways to find the filesize. This post is all about identifing the filesize using T-SQL,Instantiating OLE Objects and PowerShell. The requirement is to retrieve the size of the specified file. The return value is going to a … Continue reading

Posted in PowerShell, SQL, T-SQL | Tagged , , , , , | Leave a comment

T-SQL – Scripting Stored Procedure to Create backup copy on same database

This post is one of the request from OP. Download SQL  Backup SP in the same database The probelm statement 1:- Create a backup copy of a group of stored procedures on the same database.  Using TSQL I need to … Continue reading

Posted in SQL, T-SQL | Tagged , , , | Leave a comment

SQL – List Primary key and Concatenate composite Keys into a single row separed by comma

The following query lists all the Primary keys of all the table.  OP has requested to list all PK and composite PKs and concatenate all it’s composite PK column values into a single row separated by comma hence this post. … Continue reading

Posted in SQL | Tagged , , , | 3 Comments

SQL Jobs – Complete Information – SQL 2000/2005/2008/R2

SQL Job details – The script can be executed across all SQL version from SQL 2000 onwards. The below are the columns listed in the output ServerName ScheduleID ScheduleName IsEnabled ScheduleType Occurrence Recurrence Frequency ScheduleUsage StartDate ScheduleUsage EndDate ScheduleCreatedOn ScheduleLastModifiedOn … Continue reading

Posted in SQL | Tagged , , , | Leave a comment

SQL – Backup Report

The simple query to find the database backup status The select statment consists of ServerName dbname BackupStartDate BackupFinishDate BackupAge Size status Type The query will only run from sql 2005 and later version. Select    SERVERPROPERTY(‘ServerName’),   db.name,   CONVERT(VARCHAR(10), b.backup_start_date, 103) +   + convert(VARCHAR(8), b.backup_start_date, 14) backup_start_date,   CONVERT(VARCHAR(10), b.backup_finish_date, 103) +   + convert(VARCHAR(8), b.backup_finish_date, 14) backup_finish_date,    case          when (DATEDIFF(hour, b.backup_start_date, getdate())<24)then ‘Success’  … Continue reading

Posted in SQL, XML | Tagged | 4 Comments