473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Triggers Question

Hey every one. I have a Trigger question. Here's the senairo:

I have a database table called _1423 and another table called OLD_1423s.
When a record the _1423 table is updated via a Web page, I want that
record (before it's updated) to go into OLD_1423s as a new row.

I wrote a trigger for this, but when I update one row, it puts the
entire _1423 table into the OLD_1423s table.

How do I specify that I want the updated row only to be copied to the
OLD_1423s table? (my trigger code is below)
CREATE TRIGGER tr_archive_1423 ON [dbo].[_1423]
FOR UPDATE
AS

IF UPDATE(num_of_updates) AND @@rowcount=0 BEGIN
INSERT INTO OLD_1423s
(_1423_id,line_item,exhibit,category,system,contra ct_id,contractor_id,e
lin,title,subtitle,authority,reference,office,dd_r eq,app_code,statement_
abbr,frequency,as_of_date,first_date,sub_date,rema rks,addressees,drafts,
regs,repros,price_group,est_tot_price,prep_by,prep _date,app_by,app_date,
status,cat_other,dist_statement,addressees2,date_t ime_stamp)
SELECT
id,line_item,exhibit,category,system,contract_id,c ontractor_id,elin,tit
le,subtitle,authority,reference,office,dd_req,app_ code,statement_abbr,fr
equency,as_of_date,first_date,sub_date,remarks,add ressees,drafts,regs,re
pros,price_group,est_tot_price,prep_by,prep_date,a pp_by,app_date,status,
cat_other,dist_statement,addressees2,GetDate()
FROM _1423
RETURN
END

FYI - "num_of_updates" is a column in the _1423 table that tracks how
many times a particular row gets updated.

Your help & time is greatly appreciated.
- Jeremy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
1 1358
[posted and mailed, please reply in news]

Jeremy Capp (jc***@belzon.com) writes:
Hey every one. I have a Trigger question. Here's the senairo:

I have a database table called _1423 and another table called OLD_1423s.
When a record the _1423 table is updated via a Web page, I want that
record (before it's updated) to go into OLD_1423s as a new row.

I wrote a trigger for this, but when I update one row, it puts the
entire _1423 table into the OLD_1423s table.

How do I specify that I want the updated row only to be copied to the
OLD_1423s table? (my trigger code is below)


In a trigger you have access to two virtual tables, "inserted" and
"deleted". "inserted" includes the rows that were inserted for an
INSERT statement, and for an UPDATE table they hold the new values.
The "deleted" table holds the rows that were deleted by a DELETE
statement, and for an UPDATE statement this is where you find the
old values.

A common mistake is to assume that these tables only has one row, but
the trigger fires once per statement, so they can have many rows.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ryan | last post by:
Hello, I am pretty much a newbie with SQL server. I have what is probably a pretty stupid question. In SQL Enterprise manager, is there a way to easily see all triggers, or, even better, all...
2
by: Jack | last post by:
We are have a question about the no cascade option on before triggers. The description stays that no other triggers will be fired by the changes of a before trigger. One of our developers is...
0
by: Dave Sisk | last post by:
Hi Folks: I've got this scenario: User table/file....external triggers declared for *AFTER *INSERT, *AFTER *UPDATE, and *BEFORE *DELETE. The 3 external triggers call a SQLRPG ILE stub...
2
by: Karl O. Pinc | last post by:
Hi, I don't suppose that the todo item: Referential Integrity o Add deferred trigger queue file (Jan) Means that there will be a statement like: CREATE TRIGGER ... FOR EACH TRANSACTION
2
by: Janning Vygen | last post by:
hi PGurus, i searched the archives and read the docs, because this problem shouldn't be new. But i really don't know what to search for. i am populating a database (v7.4.1) with COPY. Some...
3
by: rick | last post by:
Hi I m new to DB2, Please bear with me if this is silly question, but i need to know how to copy(only triggers) 400 triggers from one data base to another on same server and also onto different...
3
by: satchi | last post by:
Ok this should be a simple question but it's seemingly difficult (or something's wrong w/ my SQL Server Managmenet Sudio). I have created new triggers in SQL Server 2000 by clicking on Managing...
0
debasisdas
by: debasisdas | last post by:
This thread contains some useful tips/sample codes regarding TRIGGERS in oracle, that the forum members may find useful. TRIGGERS: =============== Database trigger is a PL/SQL block that is...
4
by: --CELKO-- | last post by:
I need to convert a bunch of DB2 triggers to Oracle. Is there any kind of tools for this?
0
by: petwir | last post by:
We've got a cascading delete being used in DB2. I've built new triggers under the parent/child tables in this cascading delete relationship. So when they delete the parent, and the cascade...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.