Sql Server wont update tabe


I am trying to see what's wrong with the following update code:

UPDATE Customer
SET CustomerName = 'Tom Bailey'
where CustomerID = 109

Sql server is not reporting errors, but I get the message: (0 row(s) affected).
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It has been a while since I used SQL Server, but I'll see if I can help in some way.

The first thing I would double check is that your table has a record with CustomerID 109.
adamtraskAuthor Commented:
Thanks  olivepeople, Yes it does.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
what data type is that field?

let me take an educated guess: it' CHAR(<size>)

if that's the case, change the field to at least VARCHAR(<size>) or better to int data type
otherwise, you change your query to:

WHERE customerid = cast(109 as CHAR(<size>))
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

If you were getting a result that said the row was updated, but not seeing the change -- I would suggest you double check that you're committing the transaction.  But why you're not seeing that row get updated is beyond me.  A quick trip around the web makes your syntax appear valid to my eyes...

I doubt you'd get a response if this was the problem, but just in case I'll leave you with the following link: http://www.simple-talk.com/sql/learn-sql-server/update--basics-in-sql-server/

These examples use GO -- but that might be specific to the app used to run the query.  Interesting stuff... again, sharing it just in case.

I hope you find a speedy solution.
adamtraskAuthor Commented:

The data type is nvarchar. I attached a snap shot showing the tables design.


Thanks for your response...
AshokSr. Software EngineerCommented:
Try this first after your UPDATE

select CustomerID, CustomerName where CustomerID = 109

Do you get one row with CustomerID & CustomerName?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AshokSr. Software EngineerCommented:
Are you using Stored Procedure?

AshokSr. Software EngineerCommented:
Is CustomerName indexed?

If so, is it supposed to be UNIQUE?

adamtraskAuthor Commented:

This is embarrassing!

I just discovered that there is no column called customerName in the table. There is firstName and Lastname but on CustomerName!

My apologies to every one.

I guess SQL Server helped me make the mistake by not pointing out that column doesn't exist.

Thanks every one.... and sorry for wasting your time
adamtraskAuthor Commented:
AshokSr. Software EngineerCommented:
This type of error can be easily avoided....

That is why you need to use SELECT statement before even trying to UPDATE
sometimes after UPDATE to figure out what's going on.

Glad to see the problem was fixed.

SELECT statements are safe to use and they should be used often.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.