05.07.2007, 08:27 | #1 |
Участник
|
Я создал таблицу, а сервер создал на нее ккакойто непонятный триггер:
Код: CREATE TRIGGER "dbo"."УПРАВЛ_ Чибис$AutoOrder_TG" ON "dbo"."УПРАВЛ_ Чибис$AutoOrder" FOR DELETE, INSERT, UPDATE AS SET NOCOUNT ON DECLARE @del_count int DECLARE @ins_count int SELECT @del_count = count(*) FROM deleted SELECT @ins_count = count(*) FROM inserted IF (@del_count > 0 AND @ins_count = 0) OR UPDATE("id") OR UPDATE("ItemCode") OR UPDATE("LocationOrder") BEGIN DECLARE @v0 INTEGER DECLARE @v1 VARCHAR(30) DECLARE @v2 DECIMAL(38,20) IF @del_count > 0 BEGIN IF @ins_count > 0 BEGIN DECLARE deleted_cursor CURSOR LOCAL FOR SELECT l."LocationOrder", l."id", l."LocationOrder" FROM deleted AS l LEFT OUTER JOIN inserted AS r ON ( l."id" = r."id" AND l."ItemCode" = r."ItemCode" ) WHERE r."id" IS NULL OR r."ItemCode" IS NULL OR l."LocationOrder" <> r."LocationOrder" OR l."LocationOrder" <> r."LocationOrder" OPEN deleted_cursor FETCH NEXT FROM deleted_cursor INTO @v2, @v0, @v2 WHILE @@FETCH_STATUS = 0 BEGIN IF (@v2 <> 0) BEGIN UPDATE "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) SET "s5" = "s5" - @v2 WHERE bucket = 1 AND "f5" = @v2 AND "f1" = 0 IF @@rowcount = 0 BEGIN INSERT INTO "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) VALUES (1, @v2, 0, -@v2) END UPDATE "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) SET "s5" = "s5" - @v2 WHERE bucket = 2 AND "f5" = @v2 AND "f1" = @v0 IF @@rowcount = 0 BEGIN INSERT INTO "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) VALUES (2, @v2, @v0, -@v2) END END FETCH NEXT FROM deleted_cursor INTO @v2, @v0, @v2 END CLOSE deleted_cursor DEALLOCATE deleted_cursor END ELSE BEGIN DECLARE deleted_cursor CURSOR LOCAL FOR SELECT "id", "ItemCode", "LocationOrder" FROM deleted OPEN deleted_cursor FETCH NEXT FROM deleted_cursor INTO @v0, @v1, @v2 WHILE @@FETCH_STATUS = 0 BEGIN IF (@v2 <> 0) BEGIN UPDATE "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) SET "s5" = "s5" - @v2 WHERE bucket = 1 AND "f5" = @v2 AND "f1" = 0 IF @@rowcount = 0 BEGIN INSERT INTO "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) VALUES (1, @v2, 0, -@v2) END UPDATE "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) SET "s5" = "s5" - @v2 WHERE bucket = 2 AND "f5" = @v2 AND "f1" = @v0 IF @@rowcount = 0 BEGIN INSERT INTO "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) VALUES (2, @v2, @v0, -@v2) END END FETCH NEXT FROM deleted_cursor INTO @v0, @v1, @v2 END CLOSE deleted_cursor DEALLOCATE deleted_cursor END END IF @ins_count > 0 BEGIN IF @del_count > 0 BEGIN DECLARE inserted_cursor CURSOR LOCAL FOR SELECT l."LocationOrder", l."id", l."LocationOrder" FROM inserted AS l LEFT OUTER JOIN deleted AS r ON ( l."id" = r."id" AND l."ItemCode" = r."ItemCode" ) WHERE r."id" IS NULL OR r."ItemCode" IS NULL OR l."LocationOrder" <> r."LocationOrder" OR l."LocationOrder" <> r."LocationOrder" OPEN inserted_cursor FETCH NEXT FROM inserted_cursor INTO @v2, @v0, @v2 WHILE @@FETCH_STATUS = 0 BEGIN IF (@v2 <> 0) BEGIN UPDATE "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) SET "s5" = "s5" + @v2 WHERE bucket = 1 AND "f5" = @v2 AND "f1" = 0 IF @@rowcount = 0 BEGIN INSERT INTO "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) VALUES (1, @v2, 0, @v2) END UPDATE "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) SET "s5" = "s5" + @v2 WHERE bucket = 2 AND "f5" = @v2 AND "f1" = @v0 IF @@rowcount = 0 BEGIN INSERT INTO "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) VALUES (2, @v2, @v0, @v2) END END FETCH NEXT FROM inserted_cursor INTO @v2, @v0, @v2 END CLOSE inserted_cursor DEALLOCATE inserted_cursor END ELSE BEGIN DECLARE inserted_cursor CURSOR LOCAL FOR SELECT "id", "ItemCode", "LocationOrder" FROM inserted OPEN inserted_cursor FETCH NEXT FROM inserted_cursor INTO @v0, @v1, @v2 WHILE @@FETCH_STATUS = 0 BEGIN IF (@v2 <> 0) BEGIN UPDATE "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) SET "s5" = "s5" + @v2 WHERE bucket = 1 AND "f5" = @v2 AND "f1" = 0 IF @@rowcount = 0 BEGIN INSERT INTO "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) VALUES (1, @v2, 0, @v2) END UPDATE "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) SET "s5" = "s5" + @v2 WHERE bucket = 2 AND "f5" = @v2 AND "f1" = @v0 IF @@rowcount = 0 BEGIN INSERT INTO "УПРАВЛ_ Чибис$50097$0" WITH (SERIALIZABLE) VALUES (2, @v2, @v0, @v2) END END FETCH NEXT FROM inserted_cursor INTO @v0, @v1, @v2 END CLOSE inserted_cursor DEALLOCATE inserted_cursor END END END Подскажите пожалуста, что с этим делать? |
|