简体   繁体   English

SQL Server更新查询不起作用,但SQL表示行受到影响

[英]SQL Server update query not working, however, SQL says the rows were affected

I have a SQL Server 2000 database with a table named Voters . 我有一个SQL Server 2000数据库,其中有一个名为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' . 表中的一列(类型为varchar(10) PrecinctCode )应该具有类似于A111D109的4位数代码,但是某些行的值为'999' The rows with value '999' have the correct number in a different column ( FaultCode of type varchar(50) ). 值为'999'的行在不同的列中具有正确的数字(类型为varchar(50) FaultCode )。 I want to copy the values from FaultCode to PrecinctCode when PrecinctCode = 999 . PrecinctCode = 999时,我想将值从FaultCode复制到PrecinctCode

I ran this query 我跑了这个查询

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

A message appears saying "3031 rows affected" but the affected rows still show 999 in the PrecinctCode column. 将显示一条消息“3031行受影响”,但受影响的行在PrecinctCode列中仍显示999。 I connect to the DB with Windows Authentication under the administrator account, so I don't think its a security issue. 我使用管理员帐户下的Windows身份验证连接到数据库,因此我认为这不是安全问题。

Has anyone had an update query that would not update rows? 有没有人有更新查询,不会更新行?

EDIT 编辑

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. 谢谢。

Try doing a SELECT first so you are certain what you are asking for: 尝试先做一个SELECT,这样你就可以确定你要求的了:

SELECT FaultCode, PrecinctCode FROM Voters WHERE PrecinctCode = '999';

NB that if length of FaultCode exceeds 10 chars your UPDATE will fail. 注意,如果FaultCode的长度超过10个字符,则UPDATE将失败。

For grins please try this 对于笑容,请试试这个

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

Or try 或者试试

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

And

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

也许你应该在更新后尝试提交

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM