November 7, 2007 at 8:25 pm
Hello,
I tried to implement an insert trigger on an order entry table and a lock was subsequently imposed on the table whenever a user tried to insert an order. Once we removed that trigger, the lock problem was resolved. The trigger was like this:
CREATE TRIGGER INSERT_ORDER ON dbo.OEORDH
FOR INSERT
AS
set nocount on
INSERT INTO ACCPAC_FedEx_Middleware.dbo.tbl_ORDER
SELECT RTrim(LTrim(ORDNUMBER)) + RTrim(LTrim(ORDDATE)),
Right(RTrim(LTrim(ORDNUMBER)),Len(RTrim(LTrim(ORDNUMBER)))-3) + "M",
SHPNAME, SHPCONTACT, SHPADDR1, SHPADDR2,
SHPADDR3, SHPCITY, SHPSTATE, SHPZIP, SHPPHONE,
SHPPHONE
FROM inserted;
Why does a trigger like the above behave this way? And, most important, how do we prevent it from doing so? Please help if you can.
Karim
November 7, 2007 at 9:01 pm
Is it everything you've got in the trigger?
_____________
Code for TallyGenerator
November 7, 2007 at 9:13 pm
I don't remember which of the SSC forums I saw this on, but this is a duplicate post and the other post had some suggestions that were, apparently, ignored. Please tell us why you have ignored those suggestions or what the results of those suggestions were if you did not ignore them...
--Jeff Moden
Change is inevitable... Change for the better is not.
November 7, 2007 at 9:14 pm
Oh yeah... here it is...
http://www.sqlservercentral.com/Forums/Topic418836-169-1.aspx
--Jeff Moden
Change is inevitable... Change for the better is not.
November 7, 2007 at 9:35 pm
Yes, it's true that this is a duplicate post. There were two reasons why I posted the same question here:
1. The final reply confirmed that I was not the only one with the problem. However, it did not provide any solution. The other reply indicated that I had to commit the transaction for SQL Server to release the lock. But the table that I was updating through the trigger was outside the database that the table the trigger was fired on existed in. Yet, the table inside the database was the one that got locked.
2. It took very long for people to post replies to my question in that forum and that made me feel that I had perhaps posted my question on the wrong forum or one that had a very limited audience.
November 7, 2007 at 9:35 pm
Yes, this is all I have in it.
November 7, 2007 at 9:43 pm
Can you provide an example of your INSERT statement?
_____________
Code for TallyGenerator
November 7, 2007 at 10:01 pm
INSERT INTO dbo.Derived_DB.tbl_ORDERS
SELECT ORDER_ID, ORDER_DATE, CUSTOMER_ID
FROM OEORDH;
November 7, 2007 at 11:16 pm
Karim Hemani (11/7/2007)
Yes, it's true that this is a duplicate post. There were two reasons why I posted the same question here:1. The final reply confirmed that I was not the only one with the problem. However, it did not provide any solution. The other reply indicated that I had to commit the transaction for SQL Server to release the lock. But the table that I was updating through the trigger was outside the database that the table the trigger was fired on existed in. Yet, the table inside the database was the one that got locked.
2. It took very long for people to post replies to my question in that forum and that made me feel that I had perhaps posted my question on the wrong forum or one that had a very limited audience.
Uh huh... and you never did answer my question on the other thread... whatever...
--Jeff Moden
Change is inevitable... Change for the better is not.
November 7, 2007 at 11:22 pm
That's not inserting into the table with the insert trigger. The trigger is on dbo.OEORDH, and that insert inserts into dbo.Derived_DB.tbl_ORDERS (a very, very strange table name. The database is called dbo, the table's owner is Derived_DB and the table is tbl_ORDERS?)
Do you have an example of an insert into the table that has the trigger?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 9, 2007 at 3:10 pm
You are right. I had written it incorrectly. The reference to the table actually had to be something like the following:
Derived_DB.dbo.tbl_ORDERS
I had mistakenly swapped the database name and the identifier for the database owner.
Karim
November 9, 2007 at 3:28 pm
You did not answer the question:
Can you provide an example of your INSERT statement?
Insert into OEORDH?
_____________
Code for TallyGenerator
November 9, 2007 at 4:17 pm
Karim Hemani (11/7/2007)
INSERT INTO dbo.Derived_DB.tbl_ORDERSSELECT ORDER_ID, ORDER_DATE, CUSTOMER_ID
FROM OEORDH;
This statement is not even inserting into the table where the trigger displayed above is.
N 56°04'39.16"
E 12°55'05.25"
November 10, 2007 at 5:45 pm
Well, the trigger was actually meant to update a table residing in a different database after a row is inserted into the table residing in the current database, namely the OEORDH table. That was the very purpose behind creating the trigger.
November 12, 2007 at 12:55 am
Yes, we understand that. That is also the reason why everybody is asking you to post
1) the entire trigger (in case you posted only a part of it)
2) statement with which you insert row(s) into the OEORDH table. The statement, which will cause trigger to fire.
Then it will be possible to test and arrive at some result, how to help you.
Viewing 15 posts - 1 through 15 (of 17 total)
You must be logged in to reply to this topic. Login to reply