Jump to content

Delete row not from primary key


grilldor

Recommended Posts

No you don't absolutely need a Primary key [b]but you should have one[/b]. If you don't have one you can do a delete matching all fields for the record you are trying to delete and putting a LIMIT 1 on the end unless your trying to delete multiple records from the data base. 

Once again, you should have a PK. Even if it is an auto incrementing key.

Regards,
John Sladek
Link to comment
Share on other sites

Funny you should mention that... in fact, that's a "bug" in the old MySQL control center, and maybe MySQL administrator as well: you can't edit a record in a table without a PK, because it has no way of knowing which record you're actually playing with.
Link to comment
Share on other sites

Well, I'm working on a program and I was wondering how I can edit or delete a record in a table that did not have a primary key.  I checked phpMyAdmin and it looked to me that they were just referencing all the feilds (or at least that is what I thought) so I decided to do the same thing. I figured if the table does not have a primary key if my where clause includes ALL the feilds and values for them and I use LIMIT 1 then I would change at least one record that is exactly like the one I am looking at.  I figured the end result would still be what was intended.

-John Sladek
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.