Il Sat, 02 May 2015 04:24:12 -0700, ladius ha scritto:
> ciao a tutti, io ho la necessità di dover unire piu databse mysql in uno
> solo, ovviamente tutti i database hanno la stessa struttura
>
> pensavo di farlo tramite script, con qualcosa di simile:
>
> REPLACE INTO sa.anagrafica SELECT * FROM 2.anagrafica
> where modified_ts > today ;
>
> il problema è che ho un altra tabella (OGGETTI) struttirata cosi:
> ID E OGGETTO
>
> un altra (OGGANAG) in cui ho:
> ID_ANAG ID_OGGETTO
>
> quando eseguo quella query mi da un errore di foreign key, ma
> sincerament non capisco perche... il dato ID_OGGETTO della tabella
> OGGANAG è un dato presente nella tabella OGGETTI.
>
> l'errore che mi da è:
>
> errore sql 1451: cannot delete or update a parent row:
> s2.ogganag, constraint fk_ogganag_anagrafica foreignkey(IDANAG)
> references anagrafica(ID)
>
> ma non capisco perche debba darmi quel'errore... potete aiutarmi?
L' errore non e' tra la tabella tra OGGETTI (parent) e la tabella OGGANAG
(children) ma, come recita il messaggio di errore tra la tabella OGGANAG
(parent) e la tabella ANAGRAFICA (children) oggetto del comando REPLACE.
Dalla documentazione MySql
(
https://dev.mysql.com/doc/refman/5.0/en/replace.html) leggo:
MySQL uses the following algorithm for REPLACE (and LOAD DATA ...
REPLACE):
Try to insert the new row into the table
While the insertion fails because a duplicate-key error occurs for a
primary key or unique index:
Delete from the table the conflicting row that has the duplicate
key value
Try again to insert the new row into the table
Questo significa che vuole cancellare un record di ANAGRAFICA per poi
inserirlo dalla omonima tabella ma non puo' farlo in quanto è parent di
uno o piu' record della tabella OGGANAG.
Saluti.