Results 1 to 5 of 5

Thread: Copying a record in SQL to another table

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    7

    Copying a record in SQL to another table

    I'm not sure if I am directing this question to the right forum or not, but I will ask it anyway in hopes that someone may know the answer.

    I am in the process of writing an application that uses SQL Server 2000 to store my data. Part of the functionality of the application is the storing of historical data for each transaction. I don't want to keep that information in the same table so I've created an INDEX table for current data and a DATA table for each subsequent 'copy' or 'history' entry.

    So say that each record has the name, address, phone, notes, etc. for a customer, additionally it has a field for the date the entry was originally created and a field for the date it was modified and a field of the person who modified the entry.

    Obviously every time the record is changed in order to keep a history I need to copy the data from the INDEX table to the DATA table before using the UPDATE command to apply the new changes.

    Is there a way to do this using an SQL or VB.NET command without having to pull each field from the INDEX table to fill the DATA table? I've made both tables identical to each other for obvious reasons so that there is no problem duplicating the data.

    Any help or tips in the right direction is greatly appreciated!

    Michael

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: Copying a record in SQL to another table

    You should be able to execute a statement like this:
    INSERT INTO DATA SELECT * FROM INDEX WHERE UniqueIdFieldNameHere = UniqueIdHere
    Regards,

    - Aaron.

  3. #3
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Copying a record in SQL to another table

    In sql you want to create a trigger on the table which gets updated, set the trigger on update to insert the ID into the other table.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    7

    Re: Copying a record in SQL to another table

    Quote Originally Posted by Aaron Young
    You should be able to execute a statement like this:Regards,

    - Aaron.
    Cool, thank you very much, this worked perfectly.

    Michael

  5. #5
    Hyperactive Member xray's Avatar
    Join Date
    Jun 2003
    Location
    EgYpT
    Posts
    312

    Re: Copying a record in SQL to another table

    peace be with you

    how i can make "execute" using "adodc1" and "ado dll"

    thanks
    In the name of allah , the beneficent , the merciful

    Say (O Muhammad ): We believe in allah and that which is revealed unto us and that which was revealed unto abraham and ishmael and isaac and jacob and the tribes , and that which was vouchsafed unto moses and jesus and the prophets from their lord . we make no distinction between any of them , and unto him we have surrendered


    ---- Great Sites For You -------------------

    If you want to know some small things about islam ?

Posting Permissions

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



Click Here to Expand Forum to Full Width