|
-
Jun 16th, 2005, 10:10 AM
#1
Thread Starter
New Member
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
-
Jun 16th, 2005, 10:22 AM
#2
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.
-
Jun 16th, 2005, 10:43 AM
#3
Frenzied Member
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.
-
Jun 16th, 2005, 12:06 PM
#4
Thread Starter
New Member
Re: Copying a record in SQL to another table
 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
-
Jul 2nd, 2005, 05:07 AM
#5
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|