MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 4th, 1999, 06:46 PM
the_archer
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
For some reason when I am doing a REPLACE query, the record I am sending to the server just gets added to the end of the database as a new record, rather than replacing the one with the same uniqueid. I've checked over my source very carefully, and I can't see the bug - it IS getting the right uniqueID, it just refuses to REPLACE it.

REPLACE into users (name,email,id) VALUES ('Nice Guy','nil@nil.nil',42);

Why would this not replace record ID 42? the 'id' field is set to auto_increment primary_key.

This is driving me insane. Any help out there?

Gabe

------------------
>>>---------->

Reply With Quote
  #2  
Old October 5th, 1999, 07:40 AM
rod k
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
try "describe users;" and verify that your 'id' field is truly designated 'primary key'. If it is then your info IS being replaced. Let me illustrate:

When you use "replace" it's the same as doing an "insert" followed by a "delete" of a different row with the exception that it allows (for the moment) a repeat in a unique field.
When you do a general query (i.e. select * from table; ) you are not designating an order for the records to be returned. Usually (although there are exceptions) the records are returned in the order there were entered. Therefore, what you are seeing is the record at the end with the id '42' but if you go back and look your previous record with the id of 42 isn't there anymore between 41 and 43. (if it is then your field is not properly designated as a primary key, an index or even just as unique, because there is no way two records could contain the same info in a field that is unique).

to make it easier to spot this try ordering your query.

select * from users order by id;

HTH

Rod

[This message has been edited by rod k (edited 10-05-99).]

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > REPLACE vs INSERT

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap