SQL Server 更新查询不起作用,但是,SQL 表示行受到影响 [英] SQL Server update query not working, however, SQL says the rows were affected

查看:41
本文介绍了SQL Server 更新查询不起作用,但是,SQL 表示行受到影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SQL Server 2000 数据库,其中包含一个名为 Voters 的表.表中的一列(varchar(10) 类型的PrecinctCode)应该有一个类似于 A111 的 4 位代码D109,但有些行的值为 '999'.值为 '999' 的行在不同的列中具有正确的编号(FaultCode 类型为 varchar(50)).当 PrecinctCode = 999 时,我想将 FaultCode 中的值复制到 PrecinctCode.

I have a SQL Server 2000 database with a table named Voters. One column in the table (PrecinctCode of type varchar(10)) is supposed to have a 4 digit code similar to A111 or D109, but some rows have a value of '999'. The rows with value '999' have the correct number in a different column (FaultCode of type varchar(50)). I want to copy the values from FaultCode to PrecinctCode when PrecinctCode = 999.

我运行了这个查询

UPDATE Voters
SET PrecinctCode = FaultCode
WHERE (PrecinctCode = '999')

出现一条消息,指出3031 行受影响",但受影响的行仍会在 PrecinctCode 列中显示 999.我使用管理员帐户下的 Windows 身份验证连接到数据库,所以我认为这不是安全问题.

A message appears saying "3031 rows affected" but the affected rows still show 999 in the PrecinctCode column. I connect to the DB with Windows Authentication under the administrator account, so I don't think its a security issue.

有没有人有一个不会更新行的更新查询?

Has anyone had an update query that would not update rows?

编辑

我试过这个查询来检索架构,但它没有给我任何有用的东西.

I tried this query to retrieve the schema, it gave me nothing useful though.

SELECT  *
FROM    INFORMATION_SCHEMA.TABLES
where   TABLE_NAME like '%Voters%'

只发布表格设计可行吗?如果没有,您能告诉我要运行的查询来检索您需要的信息吗?谢谢.

Would just posting the table design work? if not can you tell me a query to run to retrieve the information you need? Thanks.

推荐答案

想笑的请试试这个

UPDATE Voters
SET PrecinctCode = FaultCode
WHERE PrecinctCode = '999' and FaultCode <> '999'

或者试试

UPDATE Voters
SET PrecinctCode = RTRIM (FaultCode)
WHERE PrecinctCode = '999' 

select *, len(FaultCode)
from Voters
WHERE PrecinctCode = '999' 
  and PrecinctCode <> FaultCode

这篇关于SQL Server 更新查询不起作用,但是,SQL 表示行受到影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆