如何复制记录,仅更改 id? [英] How can I copy a record, changing only the id?
本文介绍了如何复制记录,仅更改 id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表有很多列.我有一个复制一些数据的命令 - 将其视为克隆产品 - 但由于未来列可能会发生变化,我只想从表中选择所有内容并且只更改一列的值而不必参考其余的.
My table has a large number of columns. I have a command to copy some data - think of it as cloning a product - but as the columns may change in the future, I would like to only select everything from the table and only change the value of one column without having to refer to the rest.
例如代替:
INSERT INTO MYTABLE (
SELECT NEW_ID, COLUMN_1, COLUMN_2, COLUMN_3, etc
FROM MYTABLE)
我想要类似的东西
INSERT INTO MYTABLE (
SELECT * {update this, set ID = NEW_ID}
FROM MYTABLE)
有没有简单的方法来做到这一点?
Is there a simple way to do this?
这是 iSeries 上的 DB2 数据库,但欢迎任何平台的答案.
This is a DB2 database on an iSeries, but answers for any platform are welcome.
推荐答案
你可以这样做:
create table mytable_copy as select * from mytable;
update mytable_copy set id=new_id;
insert into mytable select * from mytable_copy;
drop table mytable_copy;
这篇关于如何复制记录,仅更改 id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文