SQL Server Trigger that works - fires just once?

If by 'manually' you mean you are copying and pasting into some User Interface tool (like an Access dataGrid) or something like that, then the tool may be issuing one insert statement per row, and in that case you are out of luck the database trigger will be executed once per insert statement. As other answers have mentioned, if you can insert the rows directly into the database, using a single insert statement, then the trigger will only fire once.

Yep I am using access – stckvrflw Jan 15 '10 at 15:06 Yes, as I thought... then I'm afraid that as long as you stick with doing this manually, through Access tableview (or whatever that's called) - you are stuck. – Charles Bretana Jan 15 '10 at 16:31.

If you have multiple inserts then it will fire for each insert you are running. If you want it to execute only once for multiple inserts you must: Write your insert on a single statement such as insert into foo select * from bar Your trigger can't be for each row Other possibility might be: Disable the trigger Perform your insertions Put the trigger code in a stored procedure Run your stored procedure.

The issue is caused because you are manually pasting the 3000 rows. You really have 2 solutions. You can turn off the trigger by doing this: ALTER TABLE tablename DISABLE TRIGGER ALL -- do work here ALTER TABLE tablename ENABLE TRIGGER ALL and then run the contents of your trigger at then end or you can put your 3000 columns into a temp table and then insert them all at once.

This will only setup 1 trigger. If this isn't enough please give us more info on what you are trying to do.

Well I didn't get your first way of solution clearly. You say that "do work here", but I am doing the work manually? What do you mean, I think I got you wrong.

Btw I am using access when copy pasting. – stckvrflw Jan 15 '10 at 15:08 I am saying run ALTER TABLE tablename DISABLE TRIGGER ALL , then paste in your rows, then run ALTER TABLE tablename ENABLE TRIGGER ALL. Once that is done you will need to run the script that is in your trigger if you want all of those rows to be updated.

– RandomBen Jan 15 '10 at 16:49.

Your trigger will not fire 3000 times if you are modifying 3000 rows in a single statement. Your trigger will fire once and there will be 3000 rows in your virtual 'deleted' table.

I think by 'manually' the OP may mean he is copying and pasting into some UI tool like an Access Grid or something like that, in which case the tool may be issuing one insert statement per row... – Charles Bretana Jan 15 '10 at 14:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions