This topic is locked

Copy Master and Detail Records

3/14/2008 1:48:04 PM
ASPRunnerPro General questions
J
JOHNF777 author

I have a Master and Detail record that I want to copy.
What's the best way of creating a "function" or event to copy the Master record and detail records?
Any suggestions?
Thanks.

G
goomba 3/14/2008

Use a stored procedure (or a Trigger) on the server. Way easier, faster and a lot cleaner.
I use them primarily for inserting records into other tables for a client when a user deletes records. IN this case,the client needs this for their internal auditing and archival business, but the theory and practice are the same.

W
Wazup 3/15/2008

johnf777, I'd use a Trigger. The reason being is that if you use a Stored Procedure (as one of goomba's suggestions), then you'd have to edit the source code.
However, a trigger is set server side on the table (add/insert/update/delete) and is called automatically by the server when one of these events occur. No Recoding.
Also (little known fact), with Triggers you can actually select from the Inserted, Deleted or Updated Sets prior to committing to the db. Kinda nice if you want to archive (or save for auditing tracks).
Hope it helps.
ps: I'm assuming you're using MS SQL, MySQL or something similar. I'm not up to speed on access - but it is SQL92+ and TSQL compliant so it should support Triggers.

J
JOHNF777 author 3/17/2008

Thanks for the responses. Good suggestions, I need to learn how to write "triggers" or "Stored Procedures". I use MS SQL for my databases.
A related question... If I do the "trigger" can you give me a sample code on how to call the stored procedure?
Thanks.