Unix Technical Forum

overwrite/don't overwrite data...

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:59 AM
maya
 
Posts: n/a
Default overwrite/don't overwrite data...

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...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:59 AM
J.O. Aho
 
Posts: n/a
Default Re: overwrite/don't overwrite data...

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 09:59 AM
maya
 
Posts: n/a
Default Re: overwrite/don't overwrite data...

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...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 09:59 AM
Kees Nuyt
 
Posts: n/a
Default Re: overwrite/don't overwrite data...

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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:24 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com