Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2002
    Posts
    8

    Unanswered: Move Row from One table to Another

    Hi,
    Is there any way i can move a single row to from one table to another [same database].
    Basically what i am trying to achive is this. I allow the user to delete a row, but instead of actuall deleting the row, i want to place it into another table [like a recycle bin], which can be restored later.

    I know i can simply use insert into statement to add it to the 2nd table and perform the delete statement on table1, but it becomes very tedious becaus there are a lot of fields in my table. I am looking for some other efficient way, if its possible at all.

    Any ideas and help is appriciated.

    Thanks

    Danial

  2. #2
    Join Date
    Feb 2002
    Posts
    43

    Re: Move Row from One table to Another

    Originally posted by Danial
    Hi,
    Is there any way i can move a single row to from one table to another [same database].
    Basically what i am trying to achive is this. I allow the user to delete a row, but instead of actuall deleting the row, i want to place it into another table [like a recycle bin], which can be restored later.

    I know i can simply use insert into statement to add it to the 2nd table and perform the delete statement on table1, but it becomes very tedious becaus there are a lot of fields in my table. I am looking for some other efficient way, if its possible at all.

    Any ideas and help is appriciated.

    Thanks

    Danial
    I think the only way to do this to do something like this:

    INSERT INTO table2 SELECT * FROM table1 where row = row id.

    this will allow you to select all fields without having to type them all. I think this is the most efficent way.

  3. #3
    Join Date
    Apr 2002
    Posts
    8

    Thumbs up

    Thanks, Thats exactly what i was looking for.

    Danial

  4. #4
    Join Date
    Oct 2010
    Posts
    7

    Code not working

    Quote Originally Posted by cmptrguru7 View Post
    I think the only way to do this to do something like this:

    INSERT INTO table2 SELECT * FROM table1 where row = row id.

    this will allow you to select all fields without having to type them all. I think this is the most efficent way.
    I tried placing this code in a on click control button and could not get it to work. Am I inserting the code in the correct place.

    Thanks Trwy

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by treypick View Post
    I tried placing this code in a on click control button and could not get it to work.
    i'm sorry, i'm not familiar with the "could not get it to work" error message

    Quote Originally Posted by treypick View Post
    Am I inserting the code in the correct place.
    i'm going to assume that you know that i can't see where in your code you inserted it, so i have to guess...

    ... and answer "probably you didn't"
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •