Simple SQL Server script to create a database and generate activity for a demo


I am doing a little demo this week and it includes a simple SQL Server script to generate activity on the network while I demo SMB2 durability.

First, the database is created:

USE [Master]
GO

CREATE DATABASE [Sales] ON  PRIMARY
( NAME = N’Sales’, FILENAME = N’\FSASQLDBSales.mdf’ ,
  SIZE = 2GB , MAXSIZE = 8GB, FILEGROWTH = 1GB )
LOG ON
( NAME = N’Sales_log’, FILENAME = N’\FSASQLDBSales_log.ldf’ ,
  SIZE = 1GB , MAXSIZE = 2GB , FILEGROWTH = 10%)
GO

USE [Sales]
GO

CREATE TABLE [dbo].[Product]
(  
 
[ProductId] [uniqueidentifier] DEFAULT NEWID() NOT NULL,
 [ProductName] [nchar](50) NULL,
 [ProductDescription] [nchar](3000) NULL,
 [ProductPrice] MONEY NULL
) ON [PRIMARY]
GO

Then, the script to keeps the database a little busy:

USE [Sales]
GO

WHILE (1=1)
  BEGIN
  TRUNCATE TABLE [Sales].[dbo].[Product]
  DECLARE @Record INT
  SET @Record=1
  WHILE @Record<=10000
  BEGIN
    INSERT INTO [Sales].[dbo].[Product]
    ([ProductName] ,[ProductDescription],[ProductPrice])
    VALUES (‘Product ‘ + STR(@Record), ‘Description ‘ + STR(@Record), @Record*100/3)
    SET @RECORD = @RECORD+1
  END
  SELECT COUNT(ProductID) as RecordsCreated FROM [Sales].[dbo].[Product]
END

Simple stuff. Just so SQL Server can generate some activity that can be shown in Task Manager’s Network tab while other things happen… 🙂

Comments (2)

  1. Anonymous says:

    I was recently faced with an interesting requirement to prov …

  2. S.D.S. Fraser says:

    I appreciate that I am a newbie to using SqlServer Jose but can I suggest that you may wish to include the version of SQL Server to which this relates sorry to say this but in previous years of downloading data from the MS web site there is a tendency to get access to a page that is largely irrelevent to my needs (currently I’m a newbie coder doing this for fun so please near with this) possibly include the versions of SQL Server can I suggest you perhaps avoid the use of 2014 and use instead 14 which might cut the size of the file to allow faster download. Best Wishes, S.D.S. Fraser, Glasgow ,Scotland