This is a discussion on overwrite/don't overwrite data... within the MySQL forums, part of the Database Server Software category; --> hi, how do you prevent MySQL from overwriting data that already exists in a table? i.e., insert into tbpb ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| hi, how do you prevent MySQL from overwriting data that already exists in a table? i.e., insert into tbpb set page='" + sBlogPg + "', photo='" + i + ".jpg', caption=''; but if, for example, there already exists a 7.jpg for page 1 don't insert that one.... thank you... |
| |||
| maya wrote: > hi, > > how do you prevent MySQL from overwriting data that already exists in a > table? > > i.e., insert into tbpb set page='" + sBlogPg + "', photo='" + i + > ".jpg', caption=''; > > but if, for example, there already exists a 7.jpg for page 1 don't > insert that one.... Either you check that first, or you make the page+photo column together to be a key. -- //Aho |
| |||
| J.O. Aho wrote: > maya wrote: >> hi, >> >> how do you prevent MySQL from overwriting data that already exists in a >> table? >> >> i.e., insert into tbpb set page='" + sBlogPg + "', photo='" + i + >> ".jpg', caption=''; >> >> but if, for example, there already exists a 7.jpg for page 1 don't >> insert that one.... > > Either you check that first, or you make the page+photo column together to be > a key. "a key"??? you mean foreign keys?? as in here? http://dev.mysql.com/doc/refman/5.0/...eign-keys.html thank you... |
| ||||
| On Fri, 08 Jun 2007 14:43:21 -0400, maya <maya778899@yahoo.com> wrote: >J.O. Aho wrote: >> maya wrote: >>> hi, >>> >>> how do you prevent MySQL from overwriting data that already exists in a >>> table? >>> >>> i.e., insert into tbpb set page='" + sBlogPg + "', photo='" + i + >>> ".jpg', caption=''; >>> >>> but if, for example, there already exists a 7.jpg for page 1 don't >>> insert that one.... >> >> Either you check that first, or you make the page+photo column together to be >> a key. > >"a key"??? you mean foreign keys?? as in here? >http://dev.mysql.com/doc/refman/5.0/...eign-keys.html Not a foreign key, but a UNIQUE constraint, like primary keys implicitly are. If you already have a primary key, add a unique index on (page,photo) or (photo,page). >thank you... -- ( Kees ) c[_] If you're happy and you know it, clunk your chains. (#137) |