Sunday, April 16, 2023

MSSQL: Create and load time series random data

 Objective: This is a very quick and simple blog post to show you how to load timeseries data to a table.


1. Choose a DB of your choce.

2. Table creation:

create table grafana2_test (dt datetime2, value int);

3. Load random data using the below TSQL command

Declare @Id int
Declare @dt2 datetime2;
Set @Id = 1
Set @dt2 = '2023-04-09 00:00:00';
While @Id <= 1000000
Begin
   Insert Into grafana2_test values (@dt2,@Id%1000)
   select @dt2 = dateadd(second,1,@dt2)
   select @Id = @Id + 1
End

This should load a 1M records of data sample ranging from 19apr2023 00 hrs onwards.

Thanks

No comments:

Post a Comment

Flashback data archive steps

 Objective: Ways to track DML changes in a table Detailed objective: We should be able to track the changes in the table at any point in tim...