Triggers - Run For Multiple Updated

Sep 24, 2005

I am new to trigger and I have following question.

I have two tables: "Customer" & "AccountDetails". "Customer" stored customer's personal information, so one customer will be at one row. "AccountDetails" stored all the accounts information which tie to each customer, so there will be multiple rows for a customer since one customer can have mulitple accounts.

Right now I have a updated trigger on "AccountDetails" table. When there is an updated to this table, it will insert some data to another "CustLog" table for logging when customer does the updates. Let's say Customer "A" has 5 accounts. When "A" updates his accounts' information, all 5 rows will be updated, triggers will be called 5 times, and 5 insert rows will be added to "CustLog". Is that any way to keep track those 5 updated on "AccountDetails" are referred to the same customer (by customer ID or so) so that it will only run the trigger once instead of 5 times?

I hope I make it clear and please help me on this! :o

View 8 Replies


ADVERTISEMENT

Update Values From Inserted Or Updated In Triggers

Mar 6, 2008

Hi all. I have this problem:

on insert in a new table a have to change one column before insert.

I wrote this trigger:

create trigger SUBSCR_ID_TRANSFER ON dbo.SalesOrderExtensionBase AFTER INSERTAS BEGIN SET NOCOUNT ON;DECLARE @OpportunityID uniqueidentifier;DECLARE @subscrId uniqueidentifier;declare @salesorderid uniqueidentifier;set @salesorderid = (select SalesorderID from inserted)SET @OpportunityID = (SELECT OpportunityId FROM SalesOrderBase where SalesOrderID=@salesorderid)SET @subscrId = (SELECT New_old_subscridId from OpportunityExtensionbase where OpportunityID=@OpportunityID)Update inserted set New_old_subscridId = @subscrIdENDbut SQL Rise the error "The inserted values can not be modified"

how to slove this issue.
Thanks.

View 5 Replies View Related

Using Triggers To Get Recently Updated Info In SQL Server 2000

Sep 30, 2004

Hello all,

I am trying to change values of two tables in my sql server 2000 database. When one of the tables is modified in some way like adding/updating a record, I need a trigger procedure to copy this new data from the first table to the second. Problem is, how do I get the newly inserted or updated data from the first table? How do I specify that I only want the data which caused the trigger to execute? Anyone know?

Thanks,
Bob

View 1 Replies View Related

Multiple Triggers On A Table Or Encapsulated Triggers

May 12, 2008

This isn€™t an problem as such, it€™s more of a debate.

If a table needs a number of update triggers which do differing tasks, should these triggers be separated out or encapsulated into one all encompassing trigger. Speaking in terms of performance, it doesn€™t make much of an improvement doing either depending upon the tasks performed. I was wondering in terms of maintenance and best practice etc. My view is that if the triggers do totally differing tasks they should be a trigger each on their own.

www.handleysonline.com

View 12 Replies View Related

Insert/Updated SP From Multiple Tables

Nov 23, 2004

How do I insert unrelated statistical data from three tables into another
table that already exist with data using an insert or update stored procedure?
OR...
How do I write an insert/Update stored procedure that has multiple select
and a where something = something statements?

This is what I have so far and it do and insert and does work and I have no idea where to begin to do an update stored procedure like this....

CREATE PROCEDURE AddDrawStats
AS
INSERT Drawing (WinnersWon,TicketsPlayed,Players,RegisterPlayers)

SELECT
WinnersWon = (SELECT Count(*) FROM Winner W INNER JOIN DrawSetting DS ON W.DrawingID = DS.CurrentDrawing WHERE W.DrawingID = DS.CurrentDrawing),

TicketsPlayed = (SELECT Count(*) FROM Ticket T INNER JOIN Student S ON T.AccountID = S.AccountID WHERE T.Active = 1),

Players = (SELECT Count(*) FROM Ticket T INNER JOIN Student S ON T.AccountID = S.AccountID WHERE T.AccountID = S.AccountID ),

RegisterPlayers = (SELECT Count(*) FROM Student S WHERE S.AccountID = S.AccountID )

FROM DrawSetting DS INNER JOIN Drawing D ON DS.CurrentDrawing = D.DrawingID

WHERE D.DrawingID = DS.CurrentDrawing
GO

View 6 Replies View Related

T-SQL (SS2K8) :: Most Updated Records From Multiple Join Query

Mar 28, 2014

i have Two tables... with both the table having LastUpdated Column. And, in my Select Query i m using both the table with inner join.And i want to show the LastUpdated column which has the maxiumum date value. i.e. ( latest Updated Column value).

View 5 Replies View Related

ERROR - The Row Value(s) Updated Or Deleted Either Do Not Make The Row Unique Or They Alter Multiple Rows.

Sep 8, 2006

i am getting the above error on my database i have 2 rows with the same info on and another 2 with the same info on.  example:

ID    username   password

1            bob       bob

1            bob       bob

1           john       john

1           john        john

 

I know this is a fault with ms sql 2005 however how do i fix it?

Ive found this link which explains everything but how do i start a query.  I tried clicking on new query and copying the code.  What is table1 meant to be?  the database is dbl.tbl_admin.  It wont find my database.

Im not sure how to do it anyway.

I need to change it though as its my admin password and Ive given it out to web design companys

http://geekswithblogs.net/allensb/archive/2006/07/27/86484.aspx

Can some 1 read the above page and give me full instructions, I dont know what im doing thanks

info@uktattoostudios.co.uk

View 7 Replies View Related

Multiple Triggers

Jul 20, 2005

When a trigger on one table updates another table, does it activatethe update trigger on the updated table?For ex:1. Table A has a trigger for update2. Table B has a trigger for update that updates table AWill the trigger no table A run when table B trigger updates table A?Thanks

View 2 Replies View Related

Multiple Update Triggers

Oct 17, 2001

What would be the best way to handle different updates for a table, multiple triggers, or just one large triggger? I am not worried about their order of firing, just that they fire

View 1 Replies View Related

One Trigger Vs Multiple Triggers ?

Aug 17, 2007



I have a question regarding Triggers.

Lets say I want to create a trigger for Insert, Update and Delete action. For each action I do different things.

Now I can create a single trigger for Insert, delete and update, and using counts for inserted and deleted table, take the action appropriately.

Or I can create three different triggers each for Insrt, update and delete.

Which option is better for performance?

Thanks



View 2 Replies View Related

Creating Multiple Triggers Is Same Sql Script

Jun 14, 2004

I'm trying to use Query Analyzer to create several triggers on different files in the same sql script file. It appears to only allow me to create one trigger at a time in Query Analyzer. How do you separate multiple create trigger statements? Here what I'm trying to do:

CREATE TRIGGER PO_BOL_DELETE ON dbo.PO_BOL
FOR DELETE
AS

INSERT into PO_Back
SELECT *, host_name(), suser_name(), getdate()
FROM deleted
GO

CREATE TRIGGER RECEIPT_DELETE ON dbo.receipt
FOR DELETE
AS

INSERT into receipt_Back
SELECT *, host_name(), suser_name(), getdate()
FROM deleted
GO

View 6 Replies View Related

Triggers Affecting Multiple Tables

May 4, 2004

I have a table "PageInfo" wich has columns "PageID, Title(has "AboutUs" as one of the values), DateModified, Active". My other table is "AboutUs" and has columns "ID, WhatsNew, Welcome, Active".

My goal here is that if table "AboutUs" is affected as an "INSERT" or an "UPDATE" on any row, I want "PageInfo.DateModified" WHERE "PageInfo.Title = AboutUs" to be updated with "getDate()". Don't know if I'm clear enough but thanks in advance.

Gazzou

View 7 Replies View Related

Triggers Prevent Updates To Multiple Records

Mar 13, 2002

I have triggers in place on a table that do various checks on data input. It is clear that because of these triggers I cannot do updates on multiple records in this table. When I do, I receive an error that "subquery returned more than one value." Is there anyway to work around this by temporarily turning off triggers or something else?

Many thanks for advice.

View 2 Replies View Related

Creating Triggers Among Multiple Database Servers

Nov 14, 2000

Hello,

I am trying to create a trigger to update a table on a different database server. (Both databases are SQL server 7.0) Does anyone know the syntax of how to implement this?

Any help is appreciated!!
Thanks,
Lisa

View 1 Replies View Related

Multiple Update Triggers Or One Large Trigger With If's

May 1, 2001

I have a table which when certain columns are updated, need a trigger to fire to update a next schedule date in that same table for that record. I can write the trigger, but my question for performance and efficiency is which approach would be better. Separate triggers fo the 8 columns, or a large trigger with an If to check if these columns are updated.
Thanks

View 1 Replies View Related

Data Driven Subscriptions - Triggers Multiple Times On Prod Servers?

Mar 7, 2008



Hey!

DDS triggers 3 - 4 times on Report Servers with 15 mints apart..any ideas?

View 3 Replies View Related

Save Updated Date When Row Is Updated

Apr 6, 2008

Hi,I want to save the last modification date when the row is updated. I have a column called "LastModification" in the table, every time the row is update I want to set the value of this column to the current date. So far all I know is that I need to use a trigger and the GetDate() function, but could any body help me with how to set the value of the column to getdate()? thanks for your help. 

View 3 Replies View Related

How To Tell If A Row Is Updated

Jan 15, 2008

Hi Im doing a simple update in my SP:     update users    set Name = @Name    where id=@userID and password=@password i want to know if a row gets updated. for example if the userID and password dont match then the row will not get updated.so i want some way to tell if a row has been updated. how do i do this?thanks  

View 3 Replies View Related

Query Cannot Be Updated Because The FROM

Apr 5, 2007

Hi everybody,
 I am a total noob conserning ASP, but I am willing to learn
We have a sql2005 SRV(hosted by our ISP, so limited access) and a ASP based forum (WEB WIZ)
When I try to login I get this error: Support Error Code:- err_SQLServer_loginUser()_update_USR_CodeFile Name:- functions_login.aspError details:-Microsoft OLE DB Provider for ODBC DriversQuery cannot be updated because the FROM clause is not a single simple table name.Can somebody tell me whats wrong?
Thanx in advance.
 Gerry de Bruijn!

View 1 Replies View Related

SQL Help: Get The Record I Just Updated

Jul 6, 2007

Hi -
 apologies if this is not the right forum for this - I've searched a bit and this seems to be the best fit.
I have the following problem: I want to update records in a table that fit certain criteria. The way the insert logic works make sure that there will always be only one record that fits the criteria and I'd like to get the ID value of that record once the update went through. So here is what I tried:
 1 UPDATE Timeslot
2 SET StartTime = @StartTime, EndTime = @EndTime
3 WHERE (ProfessionalID = @ProfessionalID) AND (ProviderLocationID = @ProviderLocationID) AND (RequestID IS NULL) AND (StartTime > @StartTime) AND
4 (EndTime < @EndTime);
5 SELECT SCOPE_IDENTITY()

 My hope was that the select scope_identity would return the Timeslot ID of the row that was affected, but it doesn't. How do I get that row?
 Thanks!!!
Oliver
 

View 12 Replies View Related

UPDATED Table

Jun 20, 2000

is there a such thing as a "UPDATED table".. as in a trigger's INSERTED table or DELETED table ....

View 1 Replies View Related

Who/When Was A Table Updated?

Apr 10, 2000

How can I determine who and when a table in a db was updated, I dont need this per record, I only need to know the last time an update was made to a table. Thanks.

View 1 Replies View Related

File Last Updated

Sep 21, 2000

Is there a way to tell when a file was last updated?

View 1 Replies View Related

Get Last Updated Records?

Jun 28, 2004

If I update a recordset a group of records using dynamic SQL where I update the TOP n records, is it possible to get the set of records that was updated?


CREATE PROCEDURE usp_Structural_ScheduleComponent
@cProject char(7),
@cComponentID char(10),
@iPour int,
@iQuantity int,
@iAvailable int OUTPUT,
@dtCast datetime OUTPUT
AS

SET @dtCast = convert(char(10), getdate(), 120)

DECLARE @cSql varchar(500)
SET @cSql = 'UPDATE tbStructuralComponentSchedule SET PourNumber = ' + CAST (@iPour AS VARCHAR) + ', ScheduledDate = ' + '''' + CAST(@dtCast AS VARCHAR) + '''' +
' WHERE EntryID IN ( SELECT TOP ' + CAST(@iQuantity AS VARCHAR) +
' FROM tbStructuralComponentSchedule ' +
' WHERE fkProjectNumber = ' + '''' + @cProject + '''' +
' AND fkComponentID = ' + '''' + @cComponentID + '''' +
' AND IssueDate IS NOT NULL' +
' AND ScheduledDate IS NULL' +
' ORDER BY EntryID DESC)'

EXEC(@cSql)
IF(@@ERROR <> 0 OR @@ROWCOUNT < = 0)
RAISERROR('Failed to add components to pour!',16,1)

SELECT @iAvailable = SUM(CASE WHEN IssueDate IS NOT NULL AND ScheduledDate IS NULL THEN 1 ELSE 0 END)
FROM tbStructuralComponentSchedule WHERE fkProjectNumber = @cProject AND fkComponentID = @cComponentID

GO

-- Is there a way to return the recordset that were modified in the update?

Mike B

View 2 Replies View Related

How To Get Last Updated Date

Oct 19, 2004

Hi,
I am looking for a function (or something else) that shows me, when a row in MS SQL Server was updated the last time. is it possible?

thanks
deviant69

View 2 Replies View Related

Updated Column Name

Feb 10, 2005

Hi,

Can anybody tell me how to find the column name(s) for recently updated table.

Thanks,

Kishore

View 6 Replies View Related

Index Not Updated.

Dec 13, 2005

Hi,

We run SQL SERVER 2000 on win2000

I've a question regarding Index on a table.
I've a table (1 milj rows) with a extra index ZINDEX1.

Now lets say I insert 1000 rows in that table.

Now what will happend if I search on these NEW rows in my table.
The Index is not updated.

//Martin

View 1 Replies View Related

Log All Updated Tables

May 3, 2006

We have a third party process that runs and updated several SQL tables.
Is there any way to find out what tables are being updated and store it in another table?

View 4 Replies View Related

When Was Db Object Last Updated?

Apr 4, 2007

Guys,

Is there a way to find out when a certain DB object (e.g. Stored procedure) was last modified?

SYSOBJECTS table contains crdate and refdate fields. None of these, however, appear to tell me when when the object was last updated.

Any suggestions?


Thanks a lot

View 1 Replies View Related

#of Rows Updated

Oct 10, 2007

Is there a command that will tell me the number of rows that are updated in a statement. I would like to put this in an Stored Procedure and pass the #rows updated back out.

View 1 Replies View Related

How To Get Last Updated Row In A Table

Mar 9, 2015

I have a table written in to sql by the program Wincc flex wich is currently constantly saving data in to it. I want to reed this data back in to Labview and update it’s content on Labview constantly to plot a graph that keeps updating over time.

I have achieved this after some research but my problem is that I need a way of just reading the last row (meaning most recent row, not last row as the bottom one) inserted in to the table written by wincc and saved in sql WITHOUT having to read all the data and selecting for example the higest value of a timestamp column (which is added by wincc) because this would cause too much lag since the table has a lot of elements and I need to constantly read it. One of the main problems is that the data written by wincc is written in a circular buffer, which does delete 20% of the data when it fill’s up and start writing new data in to the free space, so that the temporal order of the data does nothing to do (at least nothing simple) with the index order in the table. Is there anything like a method to save the index of the last row modified in the table so that labview could read it and directly access the most recent recordset in the table just by index specification on a query?

View 10 Replies View Related

Getting The Name Of The Updated Table

Mar 7, 2006

I am writing a generic trigger in VS 2005 that selects records from the inserted table, and updates an audit table. I am, however, unable to retrieve the name of the table that the insert occurred on. I am using the following code to select the records, and obtain the name.. Can anyone offer any alternatives to accomplishing this task? Thanks in advnace for any help you can provide.

Craig

SqlDataAdapter tableLoader = new SqlDataAdapter("SELECT * FROM inserted", connection);

DataTable insertedTable = new DataTable();

tableLoader.Fill(insertedTable);

string insertedTableName = insertedTable.TableName;

View 22 Replies View Related

Database Is Not Updated

Jun 12, 2007



I am trying to insert data to a simple table using SQL express

However , I can see the data saved in the DataSet but not in the actual database.

If I try to insert the same user again , I got primary key violation ???



Here is the insert function :

string SqlConnection = @"Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|QJ.mdf;Integrated Security=True;User Instance=True";

SqlConnection Conn = new SqlConnection(SqlConnection);

SqlDataAdapter DataAdapter = new SqlDataAdapter("SELECT * FROM USERS", Conn);

SqlCommandBuilder ComandBuilder = new SqlCommandBuilder(DataAdapter);

DataAdapter.InsertCommand = ComandBuilder.GetInsertCommand();

DataAdapter.UpdateCommand = ComandBuilder.GetUpdateCommand();

DataSet DS = new DataSet();

DataAdapter.Fill(DS, "USERS");

DataTable DT = DS.Tables["USERS"];

DataRow DR = DT.NewRow();

DR["NAME"] = txtUserName.Text;

DR["Password"] = txtPass.Text;

DR["Type"] = 1;

DT.Rows.Add(DR);

DataAdapter.Update(DS,"USERS");

DS.AcceptChanges();

Conn.Close();











I dont know what I have done wrong

Please help

Thanks very much

View 6 Replies View Related







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