|
| 1 | +create procedure table_copy(@tablecount int) |
| 2 | +as |
| 3 | +begin |
| 4 | +set nocount on; |
| 5 | + |
| 6 | +DECLARE @v_max_table int; |
| 7 | +DECLARE @v_counter_table int; |
| 8 | +DECLARE @tnamee VARCHAR(255); |
| 9 | +set @v_max_table = @tablecount; |
| 10 | +set @v_counter_table = 1; |
| 11 | + |
| 12 | +while @v_counter_table < @v_max_table begin |
| 13 | +set @tnamee = concat('SELECT * INTO test_', @v_counter_table, ' FROM test;'); |
| 14 | +EXEC (@tnamee); |
| 15 | +set @v_counter_table = @v_counter_table + 1; |
| 16 | +end; |
| 17 | + |
| 18 | +end; |
| 19 | +go -- |
| 20 | + |
| 21 | +create procedure insert_rows( @allrows int, @insertcount int, @value NVARCHAR(max)) |
| 22 | +as |
| 23 | +begin |
| 24 | +set nocount on; |
| 25 | + |
| 26 | +DECLARE @dummyIpsum varchar(255) |
| 27 | +DECLARE @fieldText NVARCHAR(max) |
| 28 | +set @fieldText = @value |
| 29 | +DECLARE @vmax int; |
| 30 | +DECLARE @vmaxx int; |
| 31 | +DECLARE @vmaxoneinsert int; |
| 32 | +DECLARE @counter int; |
| 33 | +DECLARE @lastinsertcounter int; |
| 34 | +DECLARE @lastinsert int; |
| 35 | +DECLARE @fullloop int; |
| 36 | +DECLARE @fullloopcounter int; |
| 37 | +set @dummyIpsum = '''dummy_ipsum''' |
| 38 | +set @vmax = @allrows; |
| 39 | +set @vmaxx = @allrows; |
| 40 | +set @vmaxoneinsert = @insertcount; |
| 41 | +set @counter = 1; |
| 42 | +set @lastinsertcounter = 1; |
| 43 | +set @lastinsert = 0; |
| 44 | +set @fullloop = 0; |
| 45 | +set @fullloopcounter = 0; |
| 46 | + |
| 47 | +while @vmaxx <= @vmaxoneinsert begin |
| 48 | + set @vmaxoneinsert = @vmaxx; |
| 49 | + set @fullloop = @fullloop + 1; |
| 50 | + set @vmaxx = @vmaxx + 1; |
| 51 | +end; |
| 52 | + |
| 53 | +while @vmax > @vmaxoneinsert begin |
| 54 | + set @fullloop = @fullloop + 1; |
| 55 | + set @vmax = @vmax - @vmaxoneinsert; |
| 56 | + set @lastinsert = @vmax; |
| 57 | +end; |
| 58 | + |
| 59 | +DECLARE @insertTable NVARCHAR(MAX) |
| 60 | +set @insertTable = CONVERT(NVARCHAR(max), 'insert into test (varchar1, varchar2, varchar3, varchar4, varchar5, longblobfield, timestampfield) values ('); |
| 61 | +while @counter < @vmaxoneinsert begin |
| 62 | + set @insertTable = CONVERT(NVARCHAR(max), concat(@insertTable, @dummyIpsum, ', ', @dummyIpsum, ', ', @dummyIpsum, ', ', @dummyIpsum, ', ', @dummyIpsum, ', ', @fieldText, ', CURRENT_TIMESTAMP), (')); |
| 63 | + set @counter = @counter + 1; |
| 64 | +end; |
| 65 | +set @insertTable = CONVERT(NVARCHAR(max), concat(@insertTable, @dummyIpsum, ', ', @dummyIpsum, ', ', @dummyIpsum, ', ', @dummyIpsum, ', ', @dummyIpsum, ', ', @fieldText, ', CURRENT_TIMESTAMP);')); |
| 66 | + |
| 67 | +while @vmax < 1 begin |
| 68 | + set @fullloop = 0 |
| 69 | + set @vmax = 1 |
| 70 | +end; |
| 71 | + |
| 72 | +while @fullloopcounter < @fullloop begin |
| 73 | + EXEC (@insertTable); |
| 74 | + set @fullloopcounter = @fullloopcounter + 1; |
| 75 | +end; |
| 76 | + |
| 77 | +DECLARE @insertTableLasted NVARCHAR(max); |
| 78 | +set @insertTableLasted = CONVERT(NVARCHAR(max), 'insert into test (varchar1, varchar2, varchar3, varchar4, varchar5, longblobfield, timestampfield) values ('); |
| 79 | +while @lastinsertcounter < @lastinsert begin |
| 80 | + set @insertTableLasted = CONVERT(NVARCHAR(max), concat(@insertTableLasted, @dummyIpsum, ', ', @dummyIpsum, ', ', @dummyIpsum, ', ', @dummyIpsum, ', ', @dummyIpsum, ', ', @fieldText, ', CURRENT_TIMESTAMP), (')); |
| 81 | + set @lastinsertcounter = @lastinsertcounter + 1; |
| 82 | +end; |
| 83 | + |
| 84 | +set @insertTableLasted = CONVERT(NVARCHAR(max), concat(@insertTableLasted, @dummyIpsum, ', ', @dummyIpsum, ', ', @dummyIpsum, ', ', @dummyIpsum, ', ', @dummyIpsum, ', ', @fieldText, ', CURRENT_TIMESTAMP);')); |
| 85 | + |
| 86 | +while @lastinsert > 0 begin |
| 87 | + EXEC (@insertTableLasted); |
| 88 | + set @lastinsert = 0; |
| 89 | +end; |
| 90 | + |
| 91 | +end; |
| 92 | +go -- |
| 93 | + |
| 94 | +create procedure table_create(@val int) |
| 95 | +as |
| 96 | +begin |
| 97 | +set nocount on; |
| 98 | + |
| 99 | +-- SQLINES LICENSE FOR EVALUATION USE ONLY |
| 100 | +create table test |
| 101 | +( |
| 102 | +id int check (id > 0) not null identity primary key, |
| 103 | +varchar1 varchar(255), |
| 104 | +varchar2 varchar(255), |
| 105 | +varchar3 varchar(255), |
| 106 | +varchar4 varchar(255), |
| 107 | +varchar5 varchar(255), |
| 108 | +longblobfield nvarchar(max), |
| 109 | +timestampfield datetime2(0) |
| 110 | +); |
| 111 | + |
| 112 | +DECLARE @extraSmallText NVARCHAR(max); |
| 113 | +DECLARE @smallText NVARCHAR(max); |
| 114 | +DECLARE @regularText NVARCHAR(max); |
| 115 | +DECLARE @largeText NVARCHAR(max); |
| 116 | +set @extraSmallText = '''test weight 50b - 50b text, 50b text, 50b text''' |
| 117 | +set @smallText = CONCAT('''test weight 500b - ', REPLICATE('some text, some text, ', 20), '''') |
| 118 | +set @regularText = CONCAT('''test weight 10kb - ', REPLICATE('some text, some text, some text, some text, ', 295), 'some text''') |
| 119 | +set @largeText = CONCAT('''test weight 100kb - ', REPLICATE('some text, some text, some text, some text, ', 2225), 'some text''') |
| 120 | +-- TODO: change the following @allrows to control the number of records with different sizes |
| 121 | +-- number of 50B records |
| 122 | +EXEC insert_rows @allrows = 0, @insertcount = 998, @value = @extraSmallText |
| 123 | +-- number of 500B records |
| 124 | +EXEC insert_rows @allrows = 0, @insertcount = 998, @value = @smallText |
| 125 | +-- number of 10KB records |
| 126 | +EXEC insert_rows @allrows = 0, @insertcount = 998, @value = @regularText |
| 127 | +-- number of 100KB records |
| 128 | +EXEC insert_rows @allrows = 0, @insertcount = 98, @value = @largeText |
| 129 | +end; |
| 130 | +go -- |
| 131 | + |
| 132 | +EXEC table_create @val = 0 |
| 133 | +drop procedure if exists insert_rows; |
| 134 | +drop procedure if exists table_create; |
| 135 | + |
| 136 | +-- TODO: change the value to control the number of tables |
| 137 | +EXEC table_copy @tablecount = 1; |
| 138 | +drop procedure if exists table_copy; |
| 139 | +exec sp_rename 'test', 'test_0'; |
0 commit comments