Fabrizio,

(still only guessing, as you did not post the table structures ...)

> i need also to change structure of the master table (have only a
primary key)  or
> the changes made on the updatable_table  are enough?

Your "updatable_table" needs to have a unique key (best is a primary
key), so REPLACE can tell whether it should INSERT a record (if there is
no unique key entry) or actually REPLACE an existing record (if there is
an entry with this key already).

Let's say you have tbl1 with your original data:

mysql> SELECT * FROM tbl1;
+----+----------+
| id | sometext |
+----+----------+
|  1 | foo      |
|  2 | bar      |
|  3 | foofoo   |
|  4 | barbar   |
+----+----------+
4 rows in set (0.00 sec)

Now, you have tbl2 with some data:

mysql> SELECT * FROM tbl2;
+----+----------+
| id | sometext |
+----+----------+
|  3 | foofoo   |
|  4 | barbar   |
+----+----------+
2 rows in set (0.00 sec)

'id' in tbl2 needs to be unique (in my case, it's the primary key), so
REPLACE will work as expected:

mysql> REPLACE INTO tbl2 SELECT * FROM tbl1;
Query OK, 4 rows affected (0.00 sec)
Datensõtze: 4  Duplikate: 2  Warnungen: 0

Note that 4 records were affected, but there were 2 duplicates. The
records with id 3 and 4 were overwritten by the REPLACE statement. Now
tbl2 has these data:

mysql> SELECT * FROM tbl2;
+----+----------+
| id | sometext |
+----+----------+
|  1 | foo      |
|  2 | bar      |
|  3 | foofoo   |
|  4 | barbar   |
+----+----------+
4 rows in set (0.01 sec)

HTH,
--
  Stefan Hinz <[EMAIL PROTECTED]>
  Geschäftsführer / CEO iConnect GmbH <http://iConnect.de>
  Heesestr. 6, 12169 Berlin (Germany)
  Tel: +49 30 7970948-0  Fax: +49 30 7970948-3

----- Original Message -----
From: "Fabrizio Tivano" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, January 24, 2003 10:50 AM
Subject: Re: updating tables


> Stefan,
>
> The problem look be solved;
>
> i've just changed structure of the updatable table.
> First this table have only 1 primary key, now my table have some
indexed unique keys.
>
> and now if i do a replace into command look's like to work fine.
>
> I have just a question:
>
> i need also to change structure of the master table (have only a
primary key)  or
> the changes made on the updatable_table  are enough?
>
>
> regards,
> fabrizio
>
>
> On Fri, 24 Jan 2003 00:10:19 +0100
> "Stefan Hinz, iConnect \(Berlin\)" <[EMAIL PROTECTED]> wrote:
>
> > Fabrizio,
> >
> > please send the table structures of table_1 and table_2 (DESCRIBE
...)
> > so we can do more for you than just guess what the problem might be.
> >
> > REPLACE seems good in the first place, but if it just INSERTs then
> > there's a problem with the (primary) keys.
> >
> > Regards,
> > --
> >   Stefan Hinz <[EMAIL PROTECTED]>
> >   Geschäftsführer / CEO iConnect GmbH <http://iConnect.de>
> >   Heesestr. 6, 12169 Berlin (Germany)
> >   Tel: +49 30 7970948-0  Fax: +49 30 7970948-3
> >
> > ----- Original Message -----
> > From: "Fabrizio Tivano" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Thursday, January 23, 2003 5:22 PM
> > Subject: updating tables
> >
> >
> > >
> > > hello dear all,
> > >
> > > i have a problem updating tables:
> > >
> > > in my queries i try to use REPLACE but  is same like INSERT
command.
> > >
> > > ...i need only to refresh table_1 with  new entries from table_2.
> > >
> > > any ideas?
> > >
> > > TIA
> > >  fabrizio
> > >
> >
> ---------------------------------------------------------------------
> > > 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
> >
>
>
> --
> Fabrizio Tivano
> WAN System Administrator
> SAD Trasporto Locale S.p.a.
> Corso Italia 13/N
> 39100 BOLZANO
>
> e-mail : [EMAIL PROTECTED]
> Tel: +390471450268
> Fax: +390471450253
>
> ---------------------------------------------------------------------
> 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

Reply via email to