【问题标题】:How to insert into sybase table querying the same table如何插入sybase表查询同一张表
【发布时间】:2015-11-26 13:59:44
【问题描述】:

我想在表中为那里已经存在的记录插入一些不同的值。我正在使用这个命令。

 insert into UserPnlCentre(userId,pnlCentreId,createdUser) values(select userId from UserPnlCentre where pnlCentreId!=4,4,'Migration')

这有什么问题?

【问题讨论】:

  • 当您使用“values”关键字时,您必须输入精确的单个值而不是结果。

标签: sybase


【解决方案1】:

试试这个:

insert into UserPnlCentre (
        userId
        , pnlCentreId
        , createdUser
)
select  userId
        , 4
        , 'Migration'
from    UserPnlCentre
where   pnlCentreId != 4

【讨论】:

  • 这给了我重复索引错误尝试在具有唯一索引'userPnlCentreIdx'的对象'UserPnlCentre'中插入重复的键行
  • 我只改变了你的插入。检查唯一索引中的列并从上面的插入脚本中消除重复
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-24
  • 1970-01-01
  • 1970-01-01
  • 2022-07-06
  • 1970-01-01
相关资源
最近更新 更多