Updating Changed Row Via Trigger In SQL Server 2000?

Jul 20, 2005

Hi All,

I'm a relatively newbie to SQL Server 2000, having come from a MySQL
background.

I'm creating my first Trigger statement on a table, and I'd like to
know how I go about performing an update on the row that was changed
when the trigger was fired.

To explain, I have 2 columns, one which contains a member number, the
other which contains a flag that is supposed to indicate whether or
not the member number in the row has changed since the last time the
table was processed for updates.

So, whenever the value in the member number field [memnum] is updated,
I want to set the flag [igproc] to true.

The best I've been able to do is:

CREATE TRIGGER [updateignoreprocflag] ON [dbo].[dd_testtable]
FOR UPDATE
AS
declare @key as int

IF UPDATE (memnum)
select @key = recid from inserted
UPDATE dd_testtable set igproc=1 where recid=@key

This seems to work, but I'd like to know if there's a better way of
retrieving the recid value of the changed row to pass to the UPDATE
statement? Also, I read somewhere in passing that using SELECT
statements and variable assignments within triggers can cause problems
when called from other applications; in this case it will either be a
web site using ASP.or an application developed in FOXPRO. I can't find
where I read this originally, so it's entirely possible I imagined it
or misunderstood it, but I'd very much appreciate it if someone could
confirm whether or not this is the case?

Many, many thanks in advance!

Much warmth,

Murray

View 2 Replies


ADVERTISEMENT

Updating Only Changed Fields

Sep 6, 2007

My client wants to minimize concurrency issues by only updating fields that the user actually changed. Whereas most update stored procedures I have created just updated all of the fields WHERE key=value, they want to update individual fields.

What I came up with so far does not look very efficient and I was wondering if anyone has suggestions for improvement.

Here is a snippet from the stored proc script:



Code Snippet
CREATE PROCEDURE dbo.DriverSaveChangedColumns
@DriverNumber VarChar(10) OUTPUT,
@CompanyName VarChar(50),
@DriverName VarChar(50),
@Address1 VarChar(50),
...
IF @CompanyName <> @Org_CompanyName

BEGIN

UPDATE Driver
SET DR_CompanyName = @CompanyName
WHERE DR_DriverNumber = @DriverNumber AND DR_CompanyName = @Org_CompanyName
END

IF @DriverName <> @Org_DriverName

BEGIN

UPDATE Driver
SET DR_DriverName = @DriverName
WHERE DR_DriverNumber = @DriverNumber AND DR_DRiverName = @Org_DriverName
END
...



Any suggestions?

The only other thing I thought of is to forget the stored procedure and do inline SQL ... but I'd rather have a proc.

Thanks!

View 15 Replies View Related

SQL2005 Prb1 -Row Cannot Be Located For Updating. Some Values May Have Been Changed

Mar 3, 2006

hi ,
I recently moved from SQL 2000 to SQL 2005.
The client side is vb6 and using Dcom dll's hosted on the db server.

I have a table which has oninsert trigger
When the recordset is updated in the com class it throws the foll error :
"Row cannot be located for updating. Some values may have been changed since it was last read."
The same code was working with SQL 2000 !!!
Any clues.

implicit tran are off on the sql 2005 server.

Thanks in advance.

View 2 Replies View Related

SQL Parameter Update Not Updating Changed Null/blank Values

Oct 24, 2006

I am attempting to update a sql db using the update and parameter code in VB.net 2003 through MSDE for a web application. It updates changed data OK, but if the textbox value is deleted, the code does not update the sql db. I am new to this, and I'm sure it is something simple. Here is some sample code.

SqlConnection1.Open()

strSQLu = "UPDATE table1 " _
& "SET Field1Tag = @Field1Tag, Field2Tag = @Field2Tag " _
& "WHERE (Field1Tag = @Field1Tag) "

cmdCategoriesUpdate.CommandText = strSQLu

With cmdCategoriesUpdate
.Parameters("@Field1Tag").Value = txtFld1.Text
.Parameters("@Field2Tag").Value = txtFld2.Text
End With
cmdCategoriesUpdate.ExecuteNonQuery()
SqlConnection1.Close()

View 3 Replies View Related

CPU Usage Changed After Upgrading To MS SQL Server 2000 From MS SQL Server 6.5

Feb 1, 2004

Hi All,

I had two Window NT 4.0 Server, say A and B... We recently upgraded from MS SQL Server 6.5 to MS SQL Server 2000 on Computer A, and for Computer B, I installed SQL Server 2000 from scratch. These two have a same RAM(512MB) and CPU speed...so the setup for hardware is almost identical...

For server A, there are around 10 connection to this SQL Server...
For server B, there are also around 10 connection to this SQL Server...

The database for SQL Server B is a copy from SQL Server A.... I restored the database on SQL Server B from the backup dump of Server A...

We have a store procedure called usp_GetMemo(ID Interger) ... we feed ID number to this store procedure and return its return Description... this table has ID column and it's Non-Cluster index, allow the duplicate row... there are 1.7 million records for this table...

Here is problem... whenever i execute more than 100 times for this store procedure(usp_GetMemo(ID)) continuously, the CPU usage of Computer A is 3 times bigger than computer B....

I did run the command "DBCC DBReindex" , "Update Statistics" for this table on computer A, but did not make any difference...

Keep in mind that Computer A has been upgraded to SQL server 2000 while Computer B installed from scratch... would that make difference somehow?? Before the upgrading, the CPU usage of computer A is the same as Computer B...

Any help will be really appreciated,
Thanks alot,
Kim,

View 7 Replies View Related

Cross Server Updating Via Trigger Issue

May 22, 2002

I need to update serverB.databaseB.tableB.columnB value
based on serverA.databaseA.tableA.columnA value change,

the update trigger in serverA.tableA works fine in
updating a testing databaseB.tableB.columnB in the same serverA.

serverB is as the linked server in ServerA and DTC is on.
when change the trigger to point to serverB.databaseB....
error:--------------------------------------------
Server: Msg 7395, Level 16, State 2, Procedure trInsUpdDel_InboundCannedMessages, Line 169
Unable to start a nested transaction for OLE DB provider 'SQLOLEDB'.
A nested transaction was required because the XACT_ABORT option was set to OFF.
[OLE/DB provider returned message: Cannot start more transactions on this session.]

thanks for the help
David

View 2 Replies View Related

SQL Trigger For Changed Columns?

Jul 20, 2005

I have never written a trigger before and now am seeing the light. Isthere a way to write a trigger so that if a user changes any column ina single row on one table then the trigger will write the value ofthis (these) rows to a second table. I don't want the unchangedcolumns, just the changed columns (with column names...)Thanks,lq

View 10 Replies View Related

Trigger To Indicate The Row Has Been Changed (updated Or Inserted)

Aug 30, 2007

Hi,

We have a column syncUpdate in some tables and we need a trigger (or one for each table) which will set the current dateTime for the syncLastUpdate (dateTime) when either the row is inserted or updated (we have to ignore the syncLastUpdate column itself as this would be an infinite loop, I think).

I don't know much about DB but I think that is easly doable.

Can anyone help me with that, please?

Cheers

View 3 Replies View Related

Trigger - Require Help For Updating A Trigger Following An INSERT On Another Table

Oct 30, 2007

Table 1





First_Name

Middle_Name

Surname


John

Ian

Lennon


Mike

Buffalo

Tyson


Tom

Finney

Jones

Table 2




ID

F

M

S

DOB


1

Athony

Harold

Wilson

24/4/67


2

Margaret

Betty

Thathcer

1/1/1808


3

John

Ian

Lennon

2/2/1979


4

Mike

Buffalo

Tyson

3/4/04


5

Tom

Finney

Jones

1/1/2000


I want to be able to create a trigger that updates table 2 when a row is inserted into table 1. However I€™m not sure how to increment the ID in table 2 or to update only the row that has been inserted.

View 17 Replies View Related

Trigger - Require Help For Updating A Trigger Following An INSERT On Another Table

Feb 5, 2008

A





ID

Name


1

Joe


2

Fred


3

Ian


4

Bill


B





ID


1


4

I want to be able to create a trigger so that when a row is inserted into table A by a specific user then the ID will appear in table B. Is it possible to find out the login id of the user inserting a row?

I believe the trigger should look something like this:

create trigger test_trigger
on a
for insert
as
insert into b(ID)

select i.id
from inserted i
where
--specific USER

View 9 Replies View Related

Updating SQL Server 2000 From ASP.net

Jun 9, 2004

I am really lost understanding using SQL Server 2000 with ASP.net Webb apps. If you are dong windows apps, the form builder wizard will either build you a page with a grid for displaying multiple records, or a single record page with text boxes.

All well and good.

With ASP.net web apps, though, you only get the option for making the gred/multiple record page.

So I try to make a page with textboxes to use to update my table in Sequel Server. I do my data binding, and fill my adapter, and viola, the data from my first row appears in the text boxes.

Here is the problem. I have a "Next" button and a "Previous" button that I want to use to move forward or backward through the rows in the table. What code do I put behind the buttons?

I created a windows app and used the dataform wizard to make a single record form. The code it puts behind the "Next" button is

Private Sub btnNavNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavNext.Click
Me.BindingContext(objDS_SclRcd, "IMA_School").Position = (Me.BindingContext(objDS_SclRcd, "IMA_School").Position + 1)
Me.objDS_SclRcd_PositionChanged()

End Sub

I tried to incorate the logic into my ASP web page, but can't figure out how to do it.

It seems like it ought to be simple, like position = position + position, but I can't figure it out.

Also, after I enter data changes, how do I save the updated data from the screen to the data set before moving on to the last record?

Last, how do I tell the dataset to go back and update the connextion server?


I really want to be able to update SQL data from a remote client usuing ASP web page, but none of my manual address how to do it.

Any help would be great.

Thanks

Jim

View 4 Replies View Related

Updating Microsoft SQL Server 2000 SP 2 To SP4

Jan 31, 2006

Greeetings!

I am newbie in SQL, asking help from you people.

We are using Microsoft SQL Server 2000 Service Pack 2 running on Windows 2000. We are planning to update service pack from to 2 to SP4...Is it okay? What are the requirements? Will there be side effects in our systems?

Hope to hear from you soon.

Regards,
Len

View 1 Replies View Related

Updating A Record On A SQL 6.5 From Data In SQL 2000 Server

Sep 30, 2004

I need to update one row in a SQL Server 6.5 DB from a row in SQL 2000 server DB. What would be the best way to do this?


I have my 2000 server defined as a Remote Server in 6.5, however I get the error message:

contains more than the maximum number of prefixes. The maximum is 2.

View 9 Replies View Related

Updating Varchar Field In SQL Server 2000

Oct 4, 2004

I would like to update a varchar field with an update statement that appends information to what is currently stored in the field, for example in the Statement field I may currently have a name (Mark) and I want to add a unique identifier to the end of the name so that it may look like, Markq1572, is there a way to do this in an update statement?

View 1 Replies View Related

Updating More Than 10000 Records SQL Server 2000

Jul 20, 2005

Hi allI just ranUPDATE dbo.tbl_forecastedSET update_ref = 0but it only updated the first 10000 records. I'm wondering if anyone cantell me why this is, and can I get around it.I have looked on google and found a few references, but nothing in too muchdetailsthanks in advanceAndy

View 2 Replies View Related

GetProcedureColumns Behavior Changed From SQLServer 2000 To 2005?

Jun 20, 2007

A stored procedure takes an IN parameter, an INOUT parameter, and returns an OUT parameter. When this stored procedure is defined in SQL Server 2000, the JDBC DatabaseMetadata method getProcedureColumns() returns three rows in the resultset:


one for the IN parameter (COLUMN_TYPE=1)
one for the INOUT parameter (COLUMN_TYPE=2), and
one for OUT parameter (COLUMN_TYPE=5).However, when the same stored procedure is defined in SQL Server 2005 (SP2), the getProcedureColumns() method returns only two rows in the resultset:


one for the IN parameter (COLUMN_TYPE=1)
one for the INOUT parameter (COLUMN_TYPE=2).No row for the OUT parameter is returned.

jTDS JDBC driver was used for both of the above tests. When the Microsoft JDBC Driver for 2005 was used against SQL Server 2005, the same behavior (only two rows in the resultset) was observed.

Has someone else run into such a problem? Is this a bug in SQL Server 2005 because the same jTDS driver works as expected against SQL Server 2000 but not against SQL Server 2005? Any feedback will be appreciated.

Thanks,

-- Damodar Periwal

View 1 Replies View Related

What System Stored Procedures Have Changed Between SQL 2000 And SQL 2005?

Aug 2, 2006

What system stored procedures have changed between SQL 2000 and SQL 2005?

View 4 Replies View Related

BOL Documentation On Sql 2000 Upgrade To Sql 2005 T-sql Changed Features

Feb 1, 2008

Some time ago I saw a section in sql 2005 BOL describing the t-sql features that have changed from sql 2000 to sql 2005. For example, some NULL handling and that "*=" is no longer supported. Can anyone find that refernece for me?


TIA,

Barkingdog

View 4 Replies View Related

Trigger In Sql Server 2000

Jan 30, 2008

How can I fire a procedure when a field is less than a threshold in sql server 2000?

Have you got any idea or suggestion?

Thanks in advance,
Andrea

View 1 Replies View Related

Sql Server 2000 Trigger

Jul 20, 2005

Hi,can someone tell how to write a Trigger; I am familiar with Sybase SqlAnywhere trigger syntax.Actually I have three tables MEMBER, CONTRACT and PAYMENTI need to update the MEMBER.BALANCE once the PAYMENT.AMOUNT is INSERTEDwhere PAYEMENT.CONTRAC_ID = CONTRACT.CONTRAC_IDand CONTRAT.MEMBER_ID = MEMBRE.MEMBER_IDI have more TRIGGERS to write, but with a good example it would be greatIn fact, send me as many examples as you canThanksFernandJoin Bytes!

View 9 Replies View Related

SQLSERVER 2000,How Can I Detect The Last Time Where The Table Has Changed (updated)?

Jan 2, 2008

Hi, I wonder where I can see last update over a table. Maybe sqlserver write some information about every table.

For example there are 300 tables in a database an I want to execute some query to see the last tables updated (list of tables updated > 2008-01-02 )

Hope to be clear,
Best regards
Ariel

View 4 Replies View Related

' The Definition Of Object [object Name] Has Changed Since It Was Compiled' Error When Altering A Trigger In 2005

Aug 17, 2007

Hello All

Not sure if this is the right forum to post this question to, so if it's not, please accept my apologies.

I'm working in SQL Server 2005 with a database that was migrated to 2005 from SQL Server 2000. I have to alter a trigger on a table for some functionality changes, and when I modify the trigger and then access it through the application the database is working with, I receive this error:


There was a error in the [stored procedure name] procedure. Error Number: -2147217900 Error Description: [Microsoft][ODBC SQL Server Driver][SQL Server]The definition of object '[trigger name]' has changed since it was compiled.


[stored procedure name] and [trigger name] are where the actual names appear in the message.

I've tried running sp_recompile on the trigger, stored procedure, and table that are associated with this, and nothing works. I have dropped the trigger, which allows the save process to complete (but doesn't perform the required functionality, of course), and then re-created the trigger, but the error message still comes up. The compatibility level for the database is SQL Server 2000 (80) (as it was migrated from SQL Server 2000 as I mentioned above).

Has anyone seen this, and if so, how can I fix it?

Thanks in advance for your help!

Jay

View 4 Replies View Related

Trigger Updating Same Table

Mar 18, 2003

Hi,

I have a Insert / Update Trigger on Table called TBL_A. Inside the trigger I am updating the same table TBL_A.

Will this cause recursion of the trigger? And will it keep on firing again and again?

Thanks in advance ...jfk

View 3 Replies View Related

Update Trigger SQL Server 2000

Sep 18, 2001

Hi Iam trying to do a trigger that everytime I Update a record de date get update too I finally find a trigger close to that, but this trigger update all the dates from all the record of the same table I wonder is there are a way that I can do it by the date of the record, if somebody could help I will really appreciate.

Thi is the trigger that I have so far

Create Trigger Update_Date
on DBO.Company After Update as
Update dbo.Company
Set ActualiizationDate=Getdate()
go

View 1 Replies View Related

Help With Update Trigger SQL Server 2000

Nov 28, 2007

Hi all,

I have a trigger for column eISBNEnteredDate on update or insert changes of eISBN of the table Products2 ( both belong to the same table). The column eISBNEnteredDate can either be added manually along with eISBN value or when only eISBN value is entered it is updated with present date.

The problem I am facing is when I send eISBN along with eISBNEnteredDate the present date is what is getting saved. Upon the same record when a new date is updated the new date is getting saved. Can someone tell me where I am going wrong?

Here is my trigger:




Code Block
ALTER TRIGGER [dbo].[Products2_eISBNEnteredDate] ON [dbo].[Products2]
For Insert, Update
As
Begin
Declare @ProductId int
Declare @eISBN Varchar(17)
Set @eISBN = '0'
If ( Update(eISBN) )
Begin
Select @Productid = I.Productid,@eISBN = I.eISBN
From Inserted I Left Join Deleted d on I.Productid = D.Productid
Left join Products2 P on P.Productid = I.Productid
Where (ISNULL(I.eISBN,'') <> ISNULL(D.eISBN,''))

If (IsNull(@eISBN,'') <> '' and IsNull(@eISBN,'') <> '0')
Begin
Update Products2
Set eISBNEnteredDate = getdate()
Where ProductID in (select i.ProductID
From Inserted i
Left join Deleted d on d.ProductID = i.ProductID
Where (i.eISBN is not null or replace(i.eISBN,' ','') != '') --where the new eISBN is not null or blank
and (d.eISBN is null or replace(d.eISBN,' ','') = '') --where the old eISBN is null or blank
and isnull(i.eISBN,'') != isnull(d.eISBN,'') --where the new eISBN is not equal to the old ISBN13
and d.eISBNEnteredDate is null)
End
If IsNull(@eISBN,'') = '' and IsNull(@eISBN,'') = ''
Begin
Update Products2
set eISBNEnteredDate = NULL
Where ProductID = @Productid
End
End
End

View 5 Replies View Related

SQL 2000 Linked Server Hangs Due To Trigger

Jul 23, 2005

Hi -We have two SQL 2000 Servers. We have the linked server setup and wecan perform updates and inserts between the databases. But when we adda trigger and insert something into a table, the database hangs. Thereare NO processes blocking or being block in either database. This ONLYoccurs when we have one OS as Windows 2000 Server and the other OS asWindows 2003 Server. This problem does not occur when both servers areWindows 2000. Has anyone ran into anything similar to this???*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!

View 2 Replies View Related

Updating Table - Trigger Duplicate Entries

Jun 12, 2014

I got error while updating a table ,duplicate entries and trigger got fired ..so how to debug the trigger to know duplicate record.

View 1 Replies View Related

Can Write More Than One Trigger For A Single Table(sql Server 2000)?

Jan 17, 2008

Hi
 
    Can u please send the answers for this
 
  1 . Can write more than one trigger for a single table(sql server 2000)?
 
  2. how to create the editable gridview? While clicking particular cell it should be  changed to
       Edit mode , and I want option for creating new row and delete option, search option
 

View 1 Replies View Related

Updating Trigger Problem : Trying To Replace The Values From The Upadate Statement

Apr 25, 2007

I am having an issue when trying to do something that looks simple on the face of it.. I want to replace the value during update in the same table.



Here's my situation



tst_update

ID int

Col1 varchar(10



I want to ensure that everytime Col1 is updated to "A" I want to set it to "X". Otherwise leave it as is.



Can someone help.



Thanks,

Ashish

View 6 Replies View Related

Updating A Table Data From Another Table Using Sql Server 2000

Jun 4, 2008

Hi All,
I have a Problem while updating one table data from another table's data using sql server 2000.
I have 2 tables named TableA(PID,SID,MinForms) , TableB(PID,SID,MinForms)
I need to update TableA with TableB's data using a single query that i have including in a stored procedure.

View 2 Replies View Related

DateTime Updating Problem In Sql 2000?

Dec 3, 2005

DateTime Updating Problem in sql?

below is the query that is a part of a sproc .All table
fields and values are ok. When the mentioned Sproc. is
called in query analyzer it executes well and update all
fields of the table used in UPDATE statement
.
UPDATE Emp_Schedule
SET IOS = 0, HoursWorked = @WorkTime, COA =getdate()
WHERE (Emp_Id = @EmpID) AND (S_Id = @ShiftId) AND (DT =@DayTime)

PROBLEM arises when i call this procedure from C# code all
fields are updated Except the COA(DateTime) field.Whats the
problem. SProc runs well both in debug mode and normal mode
in query analyzer and do updates the values. But when i
call in C# only datetime field COA is not Updated? Plz solve this.
THNX IN Advance.

View 6 Replies View Related

Replication And Direct Updating In SQL 2000

May 3, 2006

I have taken over the support over a database in sql 2000 that has 10+ remote users that synchronise each day. However it also has 30+ users who are directly updating the data in the live database on the server.

One of these users is entering data directly upon the database on the server but the new rows are being placed in the conflict table somehow!!

Does anybody have any ideas about how this could be happening ?

Is it ok to have users directly updating on the server and users synchronising ?

I would appreciate any help!!

Thanks.

View 1 Replies View Related

Problem With Inserting Or Updating Dates In Mssql 2000

Apr 12, 2006

Hello.I've read many topics about this problem but i couldn't figure it out.I use form where user must insert 2 dates  using texboxes.-One is required and other is optional.Sql 2000 is inserting either '20061105' or '2006.11.05' on insert update but select query returns 05.11.2006 on my report. Question 1.How do I insert or update dates from my form where date is entered dd.mm.yyyy to sql 2000 table?question 2. What to do if user left optional texbox date empty.I'm using SP and function with arguments (byval texbox1.text as date, byval texbox2.text as date)and parameters @date1, sqldbtype date =texbox1.text

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved