sql server - TSQL - clone records for a day -


i'm working on creating lab big mssql database. simplify problem, let's assume it's 1 table (if can find better solution, can tables)

i have data 1 day in table, between 525k , 630k records. want duplicate data different days (create history).

i've tried different ways , i'm finding long. process taking 91 hours duplicate 1 day... brought down 16 minutes process 1 day (which makes approx. 91 hours duplicate year) . i'm wondering if there tool or made duplicate data or create history quickly?

here's have right now:

    declare @idatecnt int=1,             @tmpdate datetime,             @idate int=365, -- counter create years worth of history.             @datestart datetime = '2015-12-22'     select f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, getdate() f11     #tmp_table1     table1 f1 = @datestart -- template day duplicated  while @idatecnt<=@idate begin      set @tmpdate = @datestart-@idatecnt     delete table1 f1 = @tmpdate     insert table1 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11)         select @tmpdate f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, getdate() f11         #tmp_table1      drop #tmp_table1 end  

to formulate comment answer, start creating table has datetime column, 1 row every date want populate cloned data. call tbldates. existing script:

select f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, getdate() f11 #tmp_table1 table1 f1 = @datestart -- template day duplicated      insert table1 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11)         select tbldates.dtcolumn f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, getdate() f11         #tmp_table1         crossjoin tbldates      drop #tmp_table1 end  

this create copy of data in #tmp_table1 each row in tbldates, date tbldates in f1 column (where using loop variable).


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -