I have the following table:
CREATE TABLE dummy (
thousand INT(10) UNSIGNED,
UNIQUE(thousand)
);
Is there sql syntax I can use to insert every thousandth positive integer, starting from 1 and up until 1 million? I can achieve this in php, but I was wondering if this was possible without using a stored procedure.
thousand
1
1001
2001
3001
4001
...
998001
999001
You can insert from a select statement. Using MySQL Variables, start with 1. Then, join to ANY table in your system that may have 1000 (or more) records just to generate a row. Even though not getting any actual column from such table, we just need it for the record position. Then the @sqlvar starts at 1 and is returned in column named thousand. Then, immediately add 1000 to it for the next record in the “AnyTable…”