?
Solved

Sql Server wont update tabe

Posted on 2012-03-10
11
Medium Priority
?
244 Views
Last Modified: 2012-03-10
Hi,

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).
Table-design.jpg
0
Comment
Question by:adamtrask
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 3

Expert Comment

by:olivepeople
ID: 37705392
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.
0
 

Author Comment

by:adamtrask
ID: 37705454
Thanks  olivepeople, Yes it does.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 37705493
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>))
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 3

Expert Comment

by:olivepeople
ID: 37705508
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.
0
 

Author Comment

by:adamtrask
ID: 37705856
angelIII,

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

olivepeople,

Thanks for your response...
0
 
LVL 13

Accepted Solution

by:
Ashok earned 2000 total points
ID: 37705904
Try this first after your UPDATE

select CustomerID, CustomerName where CustomerID = 109

Do you get one row with CustomerID & CustomerName?

HTH
Ashok
0
 
LVL 13

Expert Comment

by:Ashok
ID: 37705907
Are you using Stored Procedure?

Ashok
0
 
LVL 13

Expert Comment

by:Ashok
ID: 37705911
Is CustomerName indexed?

If so, is it supposed to be UNIQUE?

Ashok
0
 

Author Comment

by:adamtrask
ID: 37705916
ashok111.....

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
0
 

Author Closing Comment

by:adamtrask
ID: 37705918
Thanks
0
 
LVL 13

Expert Comment

by:Ashok
ID: 37705925
This type of error can be easily avoided....

That is why you need to use SELECT statement before even trying to UPDATE
and
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.

Ashok
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question