Too slow update (SQL Server 2000)
I have a real-time application that updates 1 table (T) in DB every 1 sec.
T contains 83 fields (mostly floats and bigints) and about 18000 records.
f0 is a primary key (VARCHAR).
Every 1 sec I have to update 2000 - 4000 records. Stored procedure that performs these updates gets data as XML.
Code:
================================================== ======
CREATE PROCEDURE MySP
@XML text
AS
SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
DECLARE @XMLDoc int
BEGIN TRANSACTION
EXEC sp_xml_preparedocument @XMLDoc OUTPUT, @XML
UPDATE MyTable
SET f1 = t.f1,
f2 = t.f2,
...........
f83 = t.f83
FROM CME_InstrumentsData, (SELECT *
FROM OPENXML (@XMLDoc, '/xml/s',1)
WITH CME_InstrumentsData) t
WHERE MyTable.f0 = t.f0
IF @@ERROR != 0 GOTO ErrorHandler
EXEC sp_xml_removedocument @XMLDoc
COMMIT TRANSACTION
SELECT 0
RETURN
ErrorHandler:
ROLLBACK TRANSACTION
SELECT -1
RETURN
GO
================================================== ======
It works, but update of 3000 records takes about 6 seconds and I have to do it for 1 second !
Is it possible to optimize this code ?
Is it good decision to pass data data as XML (data may be formatted to any standard format) ?
Thanks a lot,