如何复制任意表的一行更改一列
我需要复制一行更改 PK。 每个客户端安装中的表可能有所不同,因此我不能只枚举列。 我已经设法执行以下操作:
INSERT INTO table SELECT * FROM table WHERE PK='value'
但显然它失败了,因为我试图复制 PK。
然后我尝试:
INSERT INTO table SELECT 'newValue' AS PK, * FROM table WHERE PK='value'
它也失败了,因为列名不匹配。
我知道PK永远是第一栏,但我不确定它有多大用处。
那么……这可能吗?有什么想法吗?
I need to duplicate one row changing the PK.
The table can be different in each client installation, so I can't just enumerate the columns.
I've managed to do the following:
INSERT INTO table SELECT * FROM table WHERE PK='value'
but obviously it fails because I'm trying to duplicate the PK.
Then I tried:
INSERT INTO table SELECT 'newValue' AS PK, * FROM table WHERE PK='value'
It also failed, because the column names didn't match.
I know the PK will always be the first column, but I'm not sure it's of much use.
So... Is this possible? Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
唯一的解决方案是通过查询其列列表并排除标识列来动态构建查询(这就是为什么我假设您希望跳过 PK)。
The only solution is to build the query dynamically by querying for its list of columns and excluding identity column (which is why I'm assuming you wish to skip the PK).