-- Create the table.
CREATE TABLE TestTable (cola INT, colb CHAR(3))
GO
SET NOCOUNT ON
GO
-- Declare the variable to be used.
DECLARE @MyCounter INT-- Initialize the variable.
SET @MyCounter = 0-- Test the variable to see if the loop is finished.
WHILE (@MyCounter < 100000)
BEGIN
-- Insert a row into the table.
INSERT INTO TestTable VALUES
(@MyCounter,'aaa')
-- Increment the variable to count this iteration
-- of the loop.
SET @MyCounter = @MyCounter + 1
END
GO
SET NOCOUNT OFF
GO
CREATE TABLE TestTable (cola INT, colb CHAR(3))
GO
SET NOCOUNT ON
GO
-- Declare the variable to be used.
DECLARE @MyCounter INT-- Initialize the variable.
SET @MyCounter = 0-- Test the variable to see if the loop is finished.
WHILE (@MyCounter < 100000)
BEGIN
-- Insert a row into the table.
INSERT INTO TestTable VALUES
(@MyCounter,'aaa')
-- Increment the variable to count this iteration
-- of the loop.
SET @MyCounter = @MyCounter + 1
END
GO
SET NOCOUNT OFF
GO
教我怎么写SQL:)
declare
i integer;
k varchar2(10);
begin
for i in 1..100000 loop
k:=to_char(i);
insert into testtable (i,k);
end loop;
commit;
end;
我试了insert...select语句,好像试不出来:(
前提是你的表b已经有现成的数据才行,而且表a和表b的结构完全一样。如果没有主键,重复执行也可以。
下面的就可以不用了
例如你用循环生成了100条数据!
哪吗下面可以这样处理
!
insert into tablename()
select primary key +1,... from tablename
insert into tablename()
select primary key +1,... from tablename
..
就是这样了!
那么
insert into tablename
select a.*
from tablename a cross join tablename b这样重复做几次,我想就会到你要求的数量。