I want to add 100 rows in a single 开发者_高级运维insert, populating each field with the next in a series of numbers (and their string equivalents).
In other words, Something along these lines (myNumber would be a varchar, myOrder would be an int):
insert into myTable (myNumber, myOrder) select "0"-"99", select 1-100
I have a feeling this can't be done, but thought I'd ask.
You should be able to without creating a whole new table... Just as long as you have A table with as many records as you hope to add, even if there is no bearing on the content... You can do with MySQL query variables..
insert into YourTable ( YourSequence, YourStringVersion, field3 )
( SELECT
@seq:= @seq+1 YourSequence,
CONVERT( @seq, CHAR(8) ) YourStringVersion,
"Other Defaults" field3
FROM
(select @seq := 1) vars,
SomeTableWithAtLeast100Records limit 100 ) JustToAdd
You could write the "select 0-99, select 1-100" as a set of unions:
select 0 as num, 1 as order
union all
select 1 as num, 2 as order
and then insert based on that result set. Not a lot of fun though - best way to do this would probably be through a stored function and a cursor -- but that will be 1 row at a time.
I can't begin to imagine what problem you are trying to solve which needs that as its solution - you do seem to post a lot of enquiries with similarly odd questions.
Since you're looking for a code solution, you presumably want to do this lots of times. The short answer would be to use a procedure with a loop, or to maintain a table (could even be a subset of rows within 'myTable' then do
INSERT INTO myTable (mynumber, myorder, another)
SELECT mynumber, myorder, 'new'
FROM myTable WHERE another='TEMPLATE';
精彩评论