Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Trigger to update existing records


Trigger to update existing records

Author
Message
Minnu
Minnu
Old Hand
Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)

Group: General Forum Members
Points: 305 Visits: 950
Hi Team,

Am having a trigger, which will update a column when insert / update occurs,

for new inserting or updating records trigger is working fine, but
am having a table, which already have multiple records, how to fire the same trigger for existing records to update column using a stored procedure
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14973 Visits: 38989
Minnu (12/19/2012)
Hi Team,

Am having a trigger, which will update a column when insert / update occurs,

for new inserting or updating records trigger is working fine, but
am having a table, which already have multiple records, how to fire the same trigger for existing records to update column using a stored procedure



i think you'll have to post the table definition(CREATE TABLE....) and the CREATE TRIGGER .... commands for us to be able to give you any sort of intelligent answer.


Post that, and be more specific about what you want to update, and i'm sure we can help.

it sounds more like you want to apply the same logic in the trigger against pre-existing data that existed before the trigger was added, and much less to do with the trigger itself, but i may be reading this wrong without more details.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Minnu
Minnu
Old Hand
Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)

Group: General Forum Members
Points: 305 Visits: 950
Yes,

i want to update pre-existing data,

at present trigger is firing for only newly updated or inserted records.

i want Trigger should be fired one time for pre-existing data....



Please help
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14973 Visits: 38989
Minnu (12/19/2012)
Yes,

i want to update pre-existing data,

at present trigger is firing for only newly updated or inserted records.

i want Trigger should be fired one time for pre-existing data....



Please help

well, here's the basic framework:
1. read the trigger code.
2. copy and paste it as an UPDATE statement
3., Modify/change the where statement to affect only records that are not yet affected.

again, without details, we can only offer vague suggestions.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Minnu
Minnu
Old Hand
Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)

Group: General Forum Members
Points: 305 Visits: 950
Yes,

i want to update pre-existing data,

at present trigger is firing for only newly updated or inserted records.

i want Trigger should be fired one time for pre-existing data....



Please help
anthony.green
anthony.green
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6102 Visits: 6078
Please post code, data and expected outcome as per the second link in my signature.



Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
When a question, really isn't a question - Jeff Smith
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


Minnu
Minnu
Old Hand
Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)

Group: General Forum Members
Points: 305 Visits: 950
Am having a table called products with 4 columns, whenever any new insert or update happens,
column "Product_Name_Expiry" will be udpated with prouduct_Name : Product_expriry_date.

ID Product_Name Product_Expiry_Date Product_Name_Expiry
-- ------------ ------------------------ ---------------------------------
1001 Veh 2012-08-20 00:00:00.000 Veh : 2012-08-20 00:00:00.000
1075 STL 2012-08-20 00:00:00.000 STL : 2012-08-20 00:00:00.000
1081 TKL 2012-08-20 00:00:00.000 TKL : 2012-08-20 00:00:00.000
1569 JKT 2012-08-20 00:00:00.000 JKT : 2012-08-20 00:00:00.000

1012 Veh 2012-08-20 00:00:00.000 NULL
1013 STL 2012-08-20 00:00:00.000 NULL
1014 TKL 2012-08-20 00:00:00.000 NULL
1515 JKT 2012-08-20 00:00:00.000 NULL



ID : 1001, 1075, 1081,1569 are the new inserted / updated records, hence trigger fired and product_name_expriry,

My requirement i want to udpate proudct_name_expiry is without updating existing records "1012,1013,1014,1015"

i want a one time stored procedure to udpate existing records.
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14973 Visits: 38989
Minnu (12/20/2012)
Am having a table called products with 4 columns, whenever any new insert or update happens,
column "Product_Name_Expiry" will be udpated with prouduct_Name : Product_expriry_date.

ID Product_Name Product_Expiry_Date Product_Name_Expiry
-- ------------ ------------------------ ---------------------------------
1001 Veh 2012-08-20 00:00:00.000 Veh : 2012-08-20 00:00:00.000
1075 STL 2012-08-20 00:00:00.000 STL : 2012-08-20 00:00:00.000
1081 TKL 2012-08-20 00:00:00.000 TKL : 2012-08-20 00:00:00.000
1569 JKT 2012-08-20 00:00:00.000 JKT : 2012-08-20 00:00:00.000

1012 Veh 2012-08-20 00:00:00.000 NULL
1013 STL 2012-08-20 00:00:00.000 NULL
1014 TKL 2012-08-20 00:00:00.000 NULL
1515 JKT 2012-08-20 00:00:00.000 NULL



ID : 1001, 1075, 1081,1569 are the new inserted / updated records, hence trigger fired and product_name_expriry,

My requirement i want to udpate proudct_name_expiry is without updating existing records "1012,1013,1014,1015"

i want a one time stored procedure to udpate existing records.

so, are you going to post the CREATE TRIGGER code and the CREATE TABLE definition?
If you want to perform the same update as the trigger, we need the code of the trigger.
you undoubtedly would have had a working answer yesterday if you had the chance to post the code.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

PiMané
PiMané
Mr or Mrs. 500
Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)

Group: General Forum Members
Points: 592 Visits: 1334
If you don't have the UPDATED validation on the TRIGGER you can do a simple UPDATE [table] SET [col] = [col] and that will do nothing to your data but will fire the trigger.

Pedro



If you need to work better, try working less...
Minnu
Minnu
Old Hand
Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)

Group: General Forum Members
Points: 305 Visits: 950
Updated by below query

UPDATE [table] SET [col] = [col]

but trigger is not firing on update.

below is my trigger

CREATE TRIGGER [dbo].[Prod]
ON [dbo].[Table_Name]
AFTER INSERT,UPDATE
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search