SQL: Moving a row from one table to another.

List,

I would like to be able to move a row from one table to another table within
the same database.

Off the top of my head I suppose the SQL command would look similar to the
following...

my $sql = 'MOVE * FROM table1 WHERE unique_id = '1111'  TO table2'. FINISH

Then I would like to be able to do the following as well...

my $sql = 'INSERT INTO table2 (crud, crud, crid) VALUES ('crud', 'crud',
'crud')' FINISH

The second is possbile :)

Is the first possible?

Thanks in advance..

Regards,

Daniel Falkenberg
0
daniel
7/10/2001 6:31:22 AM
perl.beginners.cgi 3839 articles. 0 followers. Follow

2 Replies
404 Views

Similar Articles

[PageSpeed] 42

I've never seen a MOVE command, but I wouldn't put it past someone like
Micro$oft or Oracle to put in a proprietary SQL command that would allow you
to do that.  Just a word of warning: if you do find a MOVE command (or any
such proprietary command), you're binding yourself to that particular SQL
server and you'll have to do some work whenever you may want to switch
platforms.

That said, I'd stick w/ standard SQL, use the DBI module (check out its
great documentation) and write out the following pseudocode:

select * from table1 where uniqueid=####
die "No row found" if nothing found
insert into table2 values from previous select
# check and make sure it inserted (before you delete the source and is lost
forever)
die "Couldn't insert row into table2" if insert failed
delete from table1 where uniqueid=####

Check out this website: http://www.arsdigita.com/books/sql/ - pretty good
tutorial w/ some amusing pictures.

Jason

----- Original Message -----
From: "Daniel Falkenberg" <daniel.falkenberg@vintek.net>
To: <beginners-cgi@perl.org>
Sent: Tuesday, July 10, 2001 2:31 AM
Subject: SQL: Moving a row from one table to another.


> List,
>
> I would like to be able to move a row from one table to another table
within
> the same database.
>
> Off the top of my head I suppose the SQL command would look similar to the
> following...
>
> my $sql = 'MOVE * FROM table1 WHERE unique_id = '1111'  TO table2'. FINISH
>
> Then I would like to be able to do the following as well...
>
> my $sql = 'INSERT INTO table2 (crud, crud, crid) VALUES ('crud', 'crud',
> 'crud')' FINISH
>
> The second is possbile :)
>
> Is the first possible?
>
> Thanks in advance..
>
> Regards,
>
> Daniel Falkenberg

0
purdy
7/10/2001 2:32:01 PM
Daniel Falkenberg wrote in message
<2E9BFAFA5A026E4F9C5CBD0AF703644CF126@opal.vintek.net>...
>List,
>
>I would like to be able to move a row from one table to another table
within
>the same database.
>
>Off the top of my head I suppose the SQL command would look similar to the
>following...
>
>my $sql = 'MOVE * FROM table1 WHERE unique_id = '1111'  TO table2'. FINISH
>
Most implementations of SQL allow the following

INSERT INTO table2
SELECT * FROM table2
WHERE unique_id = '1111'

Dave.



0
david
7/11/2001 8:07:08 AM
Reply: