SQL script to fill a database

6 Posts
3 Users
0 Likes
22 Views
LM
 LM
(@l-micaudarcinfo-com)
Posts: 383
Member Admin
Topic starter
 

Just for information.

Together with Arnaud we created this small script to fill a PcVue database automatically.

DECLARE @countt bigint
SELECT @countt = 1

DECLARE @chrono bigint 
SELECT @chrono = 130014720000000000 // 2013-01-01T00:00:00.000Z

DECLARE @date char(255)
SELECT @date = convert(datetime, GETDATE(), 126)

WHILE @countt <= 31622400
BEGIN

 INSERT INTO BACKUP_SQL_BACKUP_DB.dbo.TRENDTABLE1
           ([Chrono]
           ,[Name]
           ,[Value]
           ,[Quality])
    VALUES(
           @Chrono,
           'MAVAR',
           @countt,
           '192')   
 SELECT @countt=@countt+1
 SELECT @chrono = @chrono + 10000000 
 CONTINUE
END

There is almost 31622400 seconds per year. This script will insert 31622400 values in the database from value 1 to 31622400.
Chrono is initialized at the first january midnight and is increasing each time per 1 second.

It takes around 10 hours to execute this script on an old computer and the database size is around 3 Gb at the end.

 
Posted : 16/07/2013 5:48 pm
n.kunzer
(@n-kunzerarcinfo-com)
Posts: 1236
Member Moderator
 

Very good!
Thanks Ludo and Arnaud

 
Posted : 17/07/2013 7:40 am
n.kunzer
(@n-kunzerarcinfo-com)
Posts: 1236
Member Moderator
 

Hey do you have the CHRONO value for // 2012-01-01T00:00:00.000Z please?

 
Posted : 17/07/2013 10:26 am
f.martin
(@f-martinarcinfo-com)
Posts: 148
Member Admin
 

Arnaud made a very usefull tool to convert Chrono to DateTime. I'll add it in the corresponding section.

 
Posted : 17/07/2013 12:24 pm
LM
 LM
(@l-micaudarcinfo-com)
Posts: 383
Member Admin
Topic starter
 

For sur you are joking Nico!

You didn't know the magic Arnaud tool??? :whistle:

 
Posted : 17/07/2013 12:26 pm
f.martin
(@f-martinarcinfo-com)
Posts: 148
Member Admin
 

He told me that he may have forgotten... That's called "wisdom" (or becoming a bit old.... :whistle: )

 
Posted : 17/07/2013 12:29 pm