SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


about triggers and bulk insert


about triggers and bulk insert

Author
Message
harish_ravi
harish_ravi
SSC Journeyman
SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)

Group: General Forum Members
Points: 82 Visits: 76
Hi
I have a query regarding trigger

I have a table Table1, and on this i have created a trigger Trg1 which will fire when we insert a row into Table1. If i want to perform bulk data insert into Table1, i will disable the trigger Trg1 and then i will do the bulk insert. and enable the trigeer.

consider a scenario where the Trigger trg1 will copy(replicate) the newly inserted data from Table1 to another table Table2.

Now please let me know how can we perform this replication of data for the bulk inserted rows
Elisabeth Rédei
Elisabeth Rédei
SSC Eights!
SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)

Group: General Forum Members
Points: 863 Visits: 788
Hi,

Are these tables part of a SQL Server replication? If not, and if it is a true copy operation, why can't you BULK INSERT to the other table as well?

/Elisabeth

elisabeth@sqlserverland.com
MCITP | MCT
http://sqlblog.com/blogs/elisabeth_redei/
http://linkedin.com/in/elisabethredei
harish_ravi
harish_ravi
SSC Journeyman
SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)

Group: General Forum Members
Points: 82 Visits: 76
Hi Thanks for your reply.
This is not part of SQL Replication.
The code in the trigger is not just copying the newly added rows. it involves some validations and then copying of newly added rows to another table.
my question is, how to run the trigger code for the newly inserted data?
Elisabeth Rédei
Elisabeth Rédei
SSC Eights!
SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)SSC Eights! (863 reputation)

Group: General Forum Members
Points: 863 Visits: 788
Hi,

Well the trigger by definition will trigger on some action so you will have to break out the code and put it in a (e.g.) stored procedure and then find some means of identifying the rows you just inserted.

If your goal is to keep the BULK INSERT operation as fast as possible, you could also BULK INSERT into an empty temporary table (not #temp table), and then run whatever code you wish on that table; inserting into both of your tables at the same time.


/Elisabeth

elisabeth@sqlserverland.com
MCITP | MCT
http://sqlblog.com/blogs/elisabeth_redei/
http://linkedin.com/in/elisabethredei
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