TSQL -> Script for producing Disk Writing activity

Here is a very simple script that produces some writing activity to the disk. It can be usefull to run it while checking the I/O perfomance via SQLServer "Peformance Monitor".

USE [colombo]
GO

-- create table for test data
IF EXISTS (SELECT *
   FROM sysobjects
   WHERE object_id = OBJECT_ID(N'[dbo].[my_test]'
   AND type IN (N 'U'))
  DROP TABLE [dbo].[my_test]
GO

CREATE TABLE [dbo].[my_test](
[ID] [int] IDENTITY(1,1) NOT NULL,
[my_string] [varchar](100) NULL,
PRIMARY KEY CLUSTERED ([ID] ASC) ON [PRIMARY]
) ON [PRIMARY]
GO


-- Run loop with 1000000 iterations
DECLARE @i INT;
DECLARE @my_str Varchar(80);
SET @i=0;

WHILE (@i < 1e6)
BEGIN

   -- do some calculations to cause CPU be a little buisy
   SET @my_str = 'AAA' + REPLACE('10100101','1','0') + 'BBB';
  
   INSERT INTO dbo.my_test (my_string)
   VALUES (@my_str);
  
   SET @i=@i+1;

END




sqlexamples.info