473,799 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trigger issue on Mass Insert/Update

3 New Member
I read topic the followoing topic: http://www.thescripts. com/forum/thread143458.ht ml

and the people attempting to help requested further code/documentation to assist in resolving the problem. I have a similar problem that I would appreciate any help with.

I have a table called EZTest which has the following five fields:
[TestID] [int] IDENTITY(1,1) NOT NULL,
[TestData1] [varchar](50)
[TestData2] [varchar](50)
[TestData3] [int] NULL,
[CRC] [int] NULL

The data in the CRC field (if you haven't guessed already) will be added via a trigger that will do a BINARY_CHECKSUM (TestID,TestDat a1,TestData2,Te stData3)

I will use the CRC field to verify if the imported data for a given row has changed and thus not import data that hasn't changed.

Data will be inserted and updated via stored procedures that will dump massive amounts of data into the table, but for our example, lets say we have 5 records in the table now and I do the following:

INSERT INTO EZTest
(TestData1,Test Data2,TestData3 )
SELECT TestData1,TestD ata2,TestData3
FROM EZTest

This should duplicate the existing data in the table.

OR

UPDATE EZTest
SET TestData2 = '3'
WHERE TestData2 = '2'



My trigger is as follows:

ALTER TRIGGER [tri_EZTest] ON [dbo].[EZTest]
FOR INSERT

AS

DECLARE @TestID int
DECLARE @CRC int

SELECT @CRC = BINARY_CHECKSUM (TestID,TestDat a1,TestData2,Te stData3)
, @TestID = i.TestID
FROM inserted i

UPDATE EZTest
SET CRC = @CRC
WHERE TestID = @TestID


-----------------
AND

ALTER TRIGGER [tru_EZTest] ON dbo.EZTest
FOR UPDATE

AS

DECLARE @TestID int
DECLARE @CRC int

SELECT @CRC = BINARY_CHECKSUM (TestID,TestDat a1,TestData2,Te stData3)
, @TestID = i.TestID
FROM inserted i

UPDATE EZTest
SET CRC = @CRC
WHERE TestID = @TestID



What I'm seeing is the first column gets updated but the rest do not.
As I said above, I'd appreciate any advice on how to best facilitate this without doing a cursor to reduce the insert to one record at a time.
Oct 27 '06 #1
1 2525
zierde01
3 New Member
I could have swore I was in the MSSQL topic area, not MySQL...should I repost, or can someone move this....very sorry...
Oct 27 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
6175
by: Gent | last post by:
am using FOR UPDATE triggers to audit a table that has 67 fields. My problem is that this slows down the system significantly. I have narrowed down the problem to the size (Lines of code) that need to be compiled after the trigger has been fired. There is about 67 IF Update(fieldName) inside the trigger and a not very complex select statement inside the if followed by an insert to the audit table. When I leave only a few IF-s in the...
7
2265
by: ZRexRider | last post by:
Hi, I have trigger that enforces the creation of a sortorder that is always 1 digit higher than the current highest on Inserts. This trigger works great if I add one row at a time so I think the logic is sound. However, I have a Stored Procedure that copies a bunch of rows into this table and all of the SortOrder values come up as 0. This stored procedure is doing an "Insert Into" and will insert numerous rows (10-20) at once.
3
7282
by: takilroy | last post by:
Hi, Does anyone know of a simple way to do this? I want to create an insert trigger for a table and if the record already exists based on some criteria, I want to update the table with the values that are passed in via the insert trigger without having to use all the 'set' statements for each field (so if we add fields in the future I won't have to update the trigger). In other words, I want the trigger code to look something like...
18
5987
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query against a different table (that uses the LIKE predicate) but cannot get around the SQL0132 error . I have tried the hex notation after the LIKE such as (without the quotes)... " where colNewPartNum like ( X'27' || nnn.colPartNum || X'27) " ,...
0
2480
by: JohnO | last post by:
Thanks to Serge and MarkB for recent tips and suggestions. Ive rolled together a few stored procedures to assist with creating audit triggers automagically. Hope someone finds this as useful as I've found it educational. Note: - I build this for use in a JDEdwards OneWorld environment. I'm not sure how generic others find it but it should be fairly generic. - I use a C stored procedure GETJOBNAME to get some extra audit data,
6
2289
by: Robert Fitzpatrick | last post by:
On 7.4.2 I have a trigger that I want to update any existing boolean values to false if a new one in that group is declare true by inserting a new record or updating an existing record: ohc=# CREATE OR REPLACE FUNCTION "public"."clear_common_groups" () RETURNS trigger AS' ohc'# BEGIN ohc'# IF NEW.common_area = ''t'' THEN ohc'# UPDATE tblhudunits SET common_area = ''f'' WHERE hud_building_id = NEW.hud_building_id;
8
7883
by: Benzine | last post by:
Hi, I have an issue with my replication at the moment. I will try to describe the scenario accurately. I am using MS SQL 2000 SP4 with Merge Replication. Subscribers connect to the publisher to upload/download changes. I have a trigger set up on one table which updates another, here is an example of the trigger: "CREATE TRIGGER qt_t_projTotal ON dbo.qt_quotes
2
4314
by: paulmac106 | last post by:
Hi, I need to update a field in about 20 records on a table. The table has an update trigger (which updates the field whenever a record is updated). As a result I'm getting an error: "Subquery returned more than 1 value.", and the update fails. Is there a way in the stored procedure to handle this issue? thanks for your help.
11
7883
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG' does not exist drop table log_errors_tab;
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.