Ma'lumotlar bazasida triggerlar mbbtda ma`lumotlar bilan ishlashda triggerlarni ishlatish


Ma`lumot jarayonlari uchun triggerlardan foydalanish



Download 1,33 Mb.
bet3/3
Sana14.07.2022
Hajmi1,33 Mb.
#800386
1   2   3
Bog'liq
za8RdOu41jgmpslzpuUsoYxa5Ba8N90jmXnI5uTn

Ma`lumot jarayonlari uchun triggerlardan foydalanish

    • Ob`yektlarni boshqarish bo`yicha operatsiyalar
        • Har bir amal uchun oldin yoki keyin tekshiriladi;
    • Elementlarni yozishni kuzatish
        • Har doim ma`lumot kiritilayotganda tekshiriladi;
    • Ma`lumotlar bzasi yaxlitligini tekshiradi
        • Ma`lumot qo`shilganda yoki o`chirilganda uning ekvalentlari to`g`risida xabar beradi;
    • Maintenance of Semantic Integrity
        • e.g. when the factory is closed, all employees should become unemployed
    • Tarkibiy ma`lumotlarni saqlash
        • masalan: kiritilayotgan ma`lumotlar ob`yektga mos bo`lishi kerak;
    • Xavfsizlikni boshqarish
        • Masalan: Foydalanuvchi imtiyozlarini tekshirish
  • SQL>CREATE OR REPLACE TRIGGER audit_emp
  • AFTER OR DELETE ON emp
  • FOR EACH ROW
  • BEGIN
  • UPDATE audit_table SET del = del + 1
  • WHERE user_name = ‘USER’
  • AND table_name = 'EMP’;
  • END;
  • /
  • SQL>CREATE OR REPLACE TRIGGER audit_emp_values
  • 2 AFTER DELETE OR UPDATE ON emp
  • 3 FOR EACH ROW
  • 4 BEGIN
  • 5 INSERT INTO audit_emp_values (user_name,
  • 6 timestamp, id, old_last_name, new_last_name,
  • 7 old_title, new_title, old_salary, new_salary)
  • 8 VALUES (USER, SYSDATE, :old.empno, :old.ename,
  • 9 :new.ename, :old.job, :new.job,
  • 10 :old.sal, :new.sal);
  • 11 END;
  • 12 /

Trigger orqali o`zgartirishga misol

  • SQL>CREATE OR REPLACE TRIGGER cascade_updates
  • 2 AFTER UPDATE OF deptno ON dept
  • 3 FOR EACH ROW
  • 4 BEGIN
  • 5 UPDATE emp
  • 6 SET emp.deptno = :new.deptno
  • 7 WHERE emp.deptno = :old.deptno;
  • 8 END
  • 9 /
  • SQL> CREATE OR REPLACE TRIGGER emp_count
  • 2 AFTER DELETE ON emp
  • 3 FOR EACH ROW
  • 4 DECLARE
  • 5 num INTEGER;
  • 6 BEGIN
  • 7 SELECT COUNT(*) INTO num FROM emp;
  • 8 DBMS_OUTPUT.PUT_LINE(' There are now ' ||
  • num || ' employees.');
  • 9 END;
  • 10 /
  • SQL> DELETE FROM emp
  • 2 WHERE deptno = 30;
  • ERROR at line 1:
  • ORA-04091: table CGMA2.EMP is mutating, trigger/
  • function may not see it
  • Trigger orqali o`zgartirishga misol

Triggerga misol

  • SQL> CREATE OR REPLACE TRIGGER emp_count
  • 2 AFTER DELETE ON emp
  • 3 -- FOR EACH ROW
  • 4 DECLARE
  • 5 num INTEGER;
  • 6 BEGIN
  • 7 SELECT COUNT(*) INTO num FROM emp;
  • 8 DBMS_OUTPUT.PUT_LINE(' There are now ' ||
  • num || ' employees.');
  • 9 END;
  • 10 /
  • SQL> DELETE FROM emp WHERE deptno = 30;
  • There are now 8 employees.
  • 6 rows deleted.

Download 1,33 Mb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish