从具有自动递增列的 table 复制

Copy from one table with auto increment column

我想将一个表1的数据复制到表2中。 table1 没有 table2 中存在的列之一,但出于我的目的,它需要是唯一的。

到目前为止我的代码是这样的:

set @uidfield=1000;

insert into table2 (column1, colulmn2, column3) 
    select column1, column2, (@uidfield := @uidfield+1) 
    from table1

这将复制大约 6000 条记录,我没有测试我的 SQL 语句的好方法,我想在将它发送给我的 SR 分析师之前确保它是正确的。

谢谢!

你在找这个吗?

insert into table2 (column1, colulmn2, column3) 
    select column1, column2, 
           1000 + row_number() over (order by (select null))
    from table1;

如果我将您的语法解释为 MySQL 语法,这将是您语法的 SQL 服务器等效项。