Long story short, I would like to create a column that repeats the pattern 1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,...etc. for (12 * 460343 =) 5524116 rows. Any wisdom on how I could complete this? Thank you!
To create a column with repeated data, set the mode of the column to REPEATED in the schema. A repeated field can be accessed as an ARRAY type in Google Standard SQL. A RECORD column can have REPEATED mode, which is represented as an array of STRUCT types.
The syntax to create a sequence in SQL Server (Transact-SQL) is: CREATE SEQUENCE [schema.] sequence_name [ AS datatype ] [ START WITH value ] [ INCREMENT BY value ] [ MINVALUE value | NO MINVALUE ] [ MAXVALUE value | NO MAXVALUE ] [ CYCLE | NO CYCLE ] [ CACHE value | NO CACHE ]; AS datatype.
The MS SQL Server uses the IDENTITY keyword to perform an auto-increment feature. In the example above, the starting value for IDENTITY is 1, and it will increment by 1 for each new record. Tip: To specify that the "Personid" column should start at value 10 and increment by 5, change it to IDENTITY(10,5) .
Syntax: CREATE SEQUENCE sequence_name START WITH initial_value INCREMENT BY increment_value MINVALUE minimum value MAXVALUE maximum value CYCLE|NOCYCLE ; sequence_name: Name of the sequence. initial_value: starting value from where the sequence starts.
Insert say 48 then select into from self several times. You will get there real fast. It is surprisingly faster than one would think.
If you create a table with an int autoinc column then at end:
delete from table where id>5524116
Edit here you go
create table idFix
( id bigint auto_increment primary key,
num int not null
)engine=myisam;
-- prime it
insert into idFix(num) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12);
-- this is pretty fast, don't laugh
-- run the following line 19 times
insert into idFix(num) select num from idFix;
-- you now have 6.2m rows (6,291,456)
select count(*) from idFix
delete from idFix where id>5524116;
select count(*) from idFix;
select min(num),max(num) from idFix;
Takes 3 minutes max
Use your helper table then for the love of Pete drop it !
Use a loop and do some mod division with your counter.
DECLARE @LoopCounter bigint
SET @LoopCounter = 0
CREATE TABLE #YourValues
(
YourValue_Key int NOT NULL identity (1,1) PRIMARY KEY,
YourValue_OneThrough12Repating int
)
WHILE @LoopCounter < 5524116
BEGIN
INSERT INTO #YourValues (YourValue_OneThrough12Repating) VALUES ((@LoopCounter % 12) + 1)
SET @LoopCounter = @LoopCounter + 1
END
SELECT * FROM #YourValues
DROP TABLE #YourValues
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With