Advertisement

12.06.2007 at 10:18AM PST, ID: 23006733
[x]
Attachment Details

Help creating a trigger

Asked by hidrau in MS SQL Server

Tags: deletes, update

Hello guys,

I don't know how exactly I can do this, an example will help me a lot:

Well, let me show you the structure of the two tables:

Table_A

CL_DATE smalldatetime
CL_NAME varchar(50)
CL_FONE varchar(20)
CL_CGC   Varchar(30)

Table_script
SC_DATE smalldatetime
SC_SCRIPT VARCHAR(3000)
SC_TYPE VARCHAR(20)

If I insert a new value in the table_A, my trigger will create a command line script to be recorded in TAB_SCRIP, then:

INSERT INTO TABLE_A (CL_DATE, CL_NAME, CL_FONE, CL_CGC)
VALUES
('20071205','ALEX','14-78459632','7418529631245')

If in TABLE_A was updated then a command line script with those fields and values must be created.

UPDATE TABLE_A SET CL_DATE=XX, CL_NAME=XX, CL_FONE=XX
WHERE CL_CGC=XX

If in TABLE_A was a row deleted, the same thing:

DELETE FROM TABLE_A WHERE CL_CGC=XX'

after create the correct script I need to record this script in my Table_script

ThanksStart Free Trial
[+][-]12.06.2007 at 11:19AM PST, ID: 20422271

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: deletes, update
Sign Up Now!
Solution Provided By: ShogunWade
Participating Experts: 1
Solution Grade: C
 
 
[+][-]12.06.2007 at 11:29AM PST, ID: 20422366

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.10.2007 at 03:54AM PST, ID: 20440766

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628