[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] SQL kopiering af records i samme tabel



In <sslug@sslug> Rasmus_Wätjen  wrote:
> I postgres har jeg en database som bl.a. indeholder to tabeller med en 
> en-til-mange relation. I tabel A findes én record for n records i 
> tabel B.
>
> Nu er det sådan at jeg gerne vil kunne kopiere en post i tabel A til 
> en  ny. Det betyder at alle n tilknyttede records i tabel B også skal 
> kopieres og have en opdateret fremmednøgle.
> 
> Er der nogen smart måde at gøre det på, eller skal man lave et udtræk, 
> rette i fremmednøgle-kolonnen og inserte påny?
> 
> Mvh Rasmus
> 
> 
begin;
create table A2 as select * from A;
create table B2 as select * from B;
commit;

alternativt om A2 och B2 finns

begin;
insert into A2 select * from A;
inseert into B2 select * from B;
commit;

eller ställer relationen till det?


/Björn


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *