هل من الأفضل أن يكون لديك مشغل واحد لإدراج / تحديث / حذف، أو متعددة؟

StackOverflow https://stackoverflow.com//questions/9639254

سؤال

لدي شرط لعكس عمليات إدراج / تحديث / حذف من جدول واحد إلى آخر. على سبيل المثال، يجب نسخ إدراج Tablea إلى TableB، وتحديث إلى Tablea المطبق على المائدة، والحذف من Tablea يتم تطبيقه على المائدة. إنه بسيط مثل ذلك، باستثناء الجدول يحتوي على عمود إضافي واحد للحصول على قيمة ثابتة، هناك حاجة إلى مشغلات بسيطة للغاية.

لست متأكدا مما إذا كان من الأفضل كتابة 3 مشغلات منفصلة، أو لديك مشغل واحد يقوم بكل عمليات.

هذا هو لمدة 3 قواعد بيانات: Sybase ASE، MSSQL و Oracle، وأرغب في الاحتفاظ بالحلول المماثل (إما إما 3 قواعد البيانات أو 1 لكل منها).

هل هي مسألة تفضيلية فقط، أن يكون لديك 3 مشغلات مقابل 1، أم أنها هناك فوائد فعلية لأي من الحل؟

هل كانت مفيدة؟

المحلول

Assuming that you actually need a trigger and that table B cannot simply be defined as a view on top of table A or that table B cannot just be defined with a foreign key that references a row in A along with the constant, that A cannot be redefined to add the additional column (potentially with a default value of the constant), one trigger at least lets you keep all the related logic in one place rather than having multiple places that need to be updated when you do something like add a new column to A. But I would be extremely wary of any architecture that involved having two different tables reflecting essentially the same data in both. That violates normalization, it adds to the system's I/O workload, and it makes the whole system more complex.

نصائح أخرى

There's no efficiency to be gained by separating the triggers, other than the loss of efficiency of the trigger execution itself, when trying to determine what the action on Table A was.

IE 3 separate triggers can employ no validation logic to determine what just occurred on Table A, since the trigger being fired itself can behave in a bubble because it knows since it's firing, it was due to single action.

Whereas a 3-in-1 trigger, you must check the status of the virtual deleted and inserted tables and derive the action each and every time it's fired.

If you're not worried about the (admittedly small) performance impact of deriving the "action", or maybe don't even need to know in Table B the "action" that just occurred on Aable A...then I think 1 is perfectly fine.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top