Subject | Re: [firebird-support] Copy records |
---|---|
Author | Martijn Tonies |
Post date | 2004-08-05T10:23:51Z |
Hi,
INSERT INTO master (ID, Name, Town) VALUES
SELECT 'ID2', Name, Town
WHERE ID = 'ID1';
You do this by inserting the rows that gets returned by
selecting the "ID1" row, but with a new ID, "ID2".
"ID2" to insert.
With regards,
Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com
> I'm pretty new to firebird (and databases at all), so execuse me, if thisis
> to basic question for this forum.course),
>
> I have two tables, master and detail. Each record in master table can have
> multiply records in detail table.
>
> Now I want to make a copy of record in master table (with new id of
> and at the same time copies of all records in detail table, which refersto
> the record from master table.First, copy the master records:
>
> Example:
>
> Master:
> ID1,Name1,Town1,...
>
> Detail
> ID1,Order1,Desc1,...
> ID1,Order2,Desc2,...
> ID1,Order3,Desc3,...
>
> After copy of record ID1 from master I want to get:
INSERT INTO master (ID, Name, Town) VALUES
SELECT 'ID2', Name, Town
WHERE ID = 'ID1';
You do this by inserting the rows that gets returned by
selecting the "ID1" row, but with a new ID, "ID2".
> Master:Next, do the same for the detail rows, but again use
> ID1,Name1,Town1,...
> ID2,Name1,Town1,...
>
> Detail
> ID1,Order1,Desc1,...
> ID1,Order2,Desc2,...
> ID1,Order3,Desc3,...
> ID2,Order1,Desc1,...
> ID2,Order2,Desc2,...
> ID2,Order3,Desc3,...
>
> Is there a simple way to do this ?
"ID2" to insert.
With regards,
Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com