Important alert: (current site time 7/15/2013 7:54:31 PM EDT)
 

VB icon

Insert Trigger

Email
Submitted on: 1/24/2001 7:56:13 AM
By: DECIS 
Level: Beginner
User Rating: By 7 Users
Compatibility: SQL Server 7.0
Views: 24354
 
     Takes Newly Inserted Values and place them in another table.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
--**************************************
-- Name: Insert Trigger
-- Description:Takes Newly Inserted Values and place them in another table.
-- By: DECIS
--
-- Inputs:just your SQL.
--
-- Returns:Inserts values into another table as they are inserted into a table.
--
-- Assumes:This code will take values from one table and place them in another as they are inserted. Just change the Select and Table Names Except the table Inserted as this is a temp table used to store values as they are inseted.
If you are an experienced DBA you probably cant belive that someone does not know how to do this, but Im no DBA just a programmer and It took me a while to figure out so I hope it can help if youre struggling as I was.
--
-- Side Effects:None.
--
--This code is copyrighted and has-- limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=269&lngWId=5--for details.--**************************************

CREATE TRIGGER [trg_Create_History_Item] ON tbl_Data_Protection
FOR INSERT
AS
INSERT INTO 
tbl_DATA_Protection_History(DP_ID,[NAME],TITLE,FORE,[INIT],SURN,THIRD_PARTIES,
THIRD_PARTIES_DTE,CONTACT,CONTACT_DTE,MAIL,MAIL_DTE,TELEPHONE,TELEPHONE_DTE,FAX,FAX_DTE,
EMAIL,EMAIL_DTE,EX_DIRECTORY,EX_DIRECTORY_DTE,TEL_NO,FAX_NO,COMPASS_KEY,FC_NOTICE_DATE)
SELECT DP_ID,[NAME],TITLE,FORE,[INIT],SURN,THIRD_PARTIES,
THIRD_PARTIES_DTE,CONTACT,CONTACT_DTE,MAIL,MAIL_DTE,TELEPHONE,TELEPHONE_DTE,FAX,FAX_DTE,
EMAIL,EMAIL_DTE,EX_DIRECTORY,EX_DIRECTORY_DTE,TEL_NO,FAX_NO,COMPASS_KEY,FC_NOTICE_DATE
FROM Inserted


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

2/1/2001 1:37:32 AMQQQ

ITs good. thanks
(If this comment was disrespectful, please report it.)

 
4/13/2002 12:01:58 PMStella Pate

I am transitioning a Access 97 database to SQL 7.0 and our GIS programmer does not want to create triggers for the tables (too much time). Do you know of any way to create triggers in Access 97 (as a module or something) that will load up on opening the Access 97 interface? HELP ASAP
04/13/02, 11:00am
stella.c.pate@exxonmobil.com
(If this comment was disrespectful, please report it.)

 
4/22/2002 8:26:24 AMDECIS

There is nothing that can be done as I am aware of. I thought you said you was transitioning to SQL 7, if this is the case wouldnt the access db become redundant ??
(If this comment was disrespectful, please report it.)

 
8/20/2002 11:58:11 AMJoey

This code really helps but I'm trying to create
a trigger that would take newly inserted table data
and find similar data in the same table where the
new data has a field left blank and if it finds
the same data where the field is not blank it will
insert that data into the newly inserted table.
Example would be zip codes but that's not what I'm
using and a lookup table wouldn't work since new
values are constantly being inserted. Actually
I'm using addresses and what zone they are in. If
anyone has created such a trigger could you
please send me a copy? Thanks
(If this comment was disrespectful, please report it.)

 
10/15/2006 1:57:40 PMhello

hiiii
(If this comment was disrespectful, please report it.)

 
1/15/2008 6:06:36 PMMurry


Thank you as your code saved the day.
I need to transfer all the data from the record being inserted to another duplicate table (history table) and here is how I used your code

CREATE TRIGGER [trg_Create_History_Item] ON tbl_Data_Protection
FOR INSERT
AS
INSERT INTO
tbl_DATA_Protection_History
SELECT *
FROM Inserted

I hope it helps some one else.

Thank You


(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.