Sql 我需要复制表中的行,其中id列是主键,id值是随机值

Sql 我需要复制表中的行,其中id列是主键,id值是随机值,sql,sql-server-2008,Sql,Sql Server 2008,我有一个500行的表,orderid列作为主键,表中的值是随机的,比如说10248102501025610258。。。。。。因此,现在我有了在2的循环中复制前50行的代码,但是orderid列将增加1,代码是 create procedure USP_CopyingDuplicateRows @loop int, @top int as Begin Declare @i int = 1,@Maxid int = 0 while(@i <= @loop) Begin select @Ma

我有一个500行的表,orderid列作为主键,表中的值是随机的,比如说10248102501025610258。。。。。。因此,现在我有了在2的循环中复制前50行的代码,但是orderid列将增加1,代码是

create procedure USP_CopyingDuplicateRows @loop int, @top int
as 
Begin
Declare  @i int = 1,@Maxid int = 0
while(@i <= @loop)
Begin
select @Maxid = max([OrderID]) from [T_MyOrders]
insert into [T_MyOrders]([OrderID],[CustomerID] ,[EmployeeID],[OrderDate],[RequiredDate] ,[ShippedDate] ,[ShipVia],[Freight] ,[ShipName] ,[ShipAddress],[ShipCity] ,[ShipRegion] ,[ShipPostalCode],[ShipCountry] )
select top (@top) @Maxid+(row_number() over( order by [OrderID])) as [OrderID],[CustomerID] ,[EmployeeID],[OrderDate],[RequiredDate] ,[ShippedDate] ,[ShipVia],[Freight] ,[ShipName] ,[ShipAddress],[ShipCity] ,[ShipRegion] ,[ShipPostalCode],[ShipCountry] 
 from T_myorders
set @i=@i+1
END
End
创建过程USP\u CopyingDuplicateRows@loop int,@top int
作为
开始
声明@i int=1,@Maxid int=0

while(@i)你有什么特别的问题要解决吗?我问,因为可能有更简单的方法来解决它。我的意思是,这就是我被赋予的任务,正如我在问题中所展示的那样,我需要这样的输出。