• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SQL Insert and Delete at same time?

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to delete a record from table_one and at the same time send it to table_two which funtions as an archive for deleted records. Currently the delete function works fine. I am using a prepared statement. Anyone know how to do this?
Thanks
Zac
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JDBC forum would be a more appropriate place for this question, but I'll give it a shot.
There is no single SQL statement that will delete a row from one table and insert it into another. However, if your database supports transactions, you can use a transaction to contain both the insert and delete statement. By doing so, the two statements are treated as an atomic operation where both statements succeed, or neither takes effect.
hth,
bear
 
Zac Roberts
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear, unfortunately I am using Microsoft Access becuase this is a very small in house JSP Database application (only 5 users max). I don't think Access supports anything like this but maybe I am wrong. I suppose I could try to add some code to my method (contained in a bean) that contains the delete statement but it would become very messy. Hmmm...
 
reply
    Bookmark Topic Watch Topic
  • New Topic