REPLACE is different than UPDATE - replace deletes the row and then inserts
a new one. Update updates the values in the existing row. Big difference
if you aren't updating all columns...
----- Original Message -----
From: "Rene Tegel" <[EMAIL PROTECTED]>
To: "Torgil Zechel" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, September 13, 2001 8:03 AM
Subject: Re: UPDATE with automatic INSERT if not found..
> check the replace syntax:
>
>
http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#REP
LACE
>
> regards
>
> rene
>
>
> On Thu, 13 Sep 2001 13:40:44 +0200
> "Torgil Zechel" <[EMAIL PROTECTED]> wrote:
>
> > Hi!
> >
> > I have a counter that is increased each time an event occur. The number
of
> > events should be reported as events / month, so along with the counter i
> > have a date-field. The table structure looks like this:
> >
> > table stats
> > count int unsigned not null default 0
> > date timestamp (using only year/month part)
> >
> > I update this table with:
> >
> > UPDATE stats SET count=count+1 WHERE date=XXX
> >
> > BUT, if the date is not there, no counter will be updated so I must
first
> > check this and insert a record if date is not found. Since there is more
> > than one thread that can write to this table I must use a lock:
> >
> > LOCK TABLES stats WRITE
> > SELECT COUNT(*) FROM stats WHERE date=XXX
> >
> > if count == 0
> > INSERT INTO stats ...
> > else
> > UPDATE stats ...
> >
> > UNLOCK TABLES
> >
> > Can this be specified as one statement, so that I dont have to use table
> > locks??
> >
> > Thanks!
> >
> > /torgil
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > Before posting, please check:
> > http://www.mysql.com/manual.php (the manual)
> > http://lists.mysql.com/ (the list archive)
> >
> > To request this thread, e-mail <[EMAIL PROTECTED]>
> > To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
> ---------------------------------------------------------------------
> Before posting, please check:
> http://www.mysql.com/manual.php (the manual)
> http://lists.mysql.com/ (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php