Forum Moderators: coopster

Message Too Old, No Replies

Overwrite mysql fields

         

opiston

11:57 am on Aug 17, 2005 (gmt 0)

10+ Year Member



Hi all,
I haven't seen you guys for a while. How's everyone doing?

I have a question about overwriting mysql fields.
Is it possible to overwrite an existing field in mysql?
Let's say I have a table name "TEST" and I have a field in there "TEXT".
If I have some text in row one of "TEXT" already, and I want to change the content of the text in row one. Is there a way to overwrite it? Or do I have to delete the whole row and rewrite the text again.

If I do have to delete the whole row, then how to delete only the middle row instead of trucating the whole table.

Regards
Opiston

mcibor

12:09 pm on Aug 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



UPDATE test SET text='Bla bla new text here' WHERE id='1';

Or if you don't know the id, but old text then:

UPDATE test SET text='Bla bla new text here' WHERE text='Here was old text';

However the query UPDATE updates all rows that match!
To delete any row:

DELETE FROM test WHERE id='1';

your table should have id:
CREATE TABLE test(id INT NOT NULL auto_increment, text TEXT, PRIMARY KEY(id));

BTW I'm not sure that it's ok to name the field "text" as it may be a keyword. Better rename it to
ALTER TABLE test CHANGE text my_text TEXT;
Best regards
Michal Cibor

opiston

9:10 am on Aug 18, 2005 (gmt 0)

10+ Year Member



Hi mcibor,
Thanks for helping again
I tried something similar to
DELETE FROM test WHERE id='1';
, but it didn't work for some reason. I will try it again tonight.

As for

UPDATE test SET text='Bla bla new text here' WHERE id='1';
, I didn't know such thing as UPDATE, thank you for sharing this knowledge.

I didn't name the field as text, I was using it as an example. I guess it's an bad example, and thanks for reminding.

Best Regards
Opiston