1. Trang chủ
  2. » Công Nghệ Thông Tin

Triggers intro trungtt

10 716 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 1,07 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Jennifer Widom Constraints Triggers Triggers – Introduction Jennifer Widom Triggers Triggers “EventConditionAction Rules” When event occurs, check condition; if true, do action 1) Move monitoring logic from apps into DBMS 2) Enforce constraints  Beyond what constraint system supports  Automatic constraint “repair”  Implementations vary significantly This intro: SQL standard Demo: SQLite Jennifer Widom Triggers in SQL Create Trigger name Before|After|Instead Of events referencingvariables For Each Row When ( condition ) action Triggers Jennifer Widom Referential Integrity: R.A references S.B, cascaded delete Create Trigger Cascade After Delete On S Referencing Old Row As O For Each Row no condition Delete From R Where A = O.B Triggers Jennifer Widom Referential Integrity: R.A references S.B, cascaded delete Create Trigger Cascade After Delete On S Referencing Old Row As O For Each Row no condition Delete From R Where A = O.B Triggers Jennifer Widom Referential Integrity: R.A references S.B, cascaded delete Create Trigger Cascade After Delete On S Referencing Old Table As OT For Each Row no condition Delete From R Where A = O.B Triggers Jennifer Widom Referential Integrity: R.A references S.B, cascaded delete Create Trigger Cascade After Delete On S Referencing Old Table As OT For Each Row no condition Delete From R Where A in (select B from OT) Triggers Jennifer Widom Triggers Tricky Issues  Rowlevel vs. Statementlevel – NewOld Row and NewOld Table – Before, Instead Of  Multiple triggers activated at same time  Trigger actions activating other triggers (chaining) – Also selftriggering, cycles, nested invocations  Conditions in When vs. as part of action  Implementations vary significantly Jennifer Widom T(K,V) – K key, V value  No statementlevel equivalent  Nondeterministic final state Create Trigger IncreaseInserts After Insert On T Referencing New Row As NR, New Table As NT For Each Row When (Select Avg(V) From T) < (Select Avg(V) From NT) Update T set V=V+10 where K=NR.K Triggers Jennifer Widom Triggers Triggers “EventConditionAction Rules” When event occurs, check condition; if true, do action 1) Move monitoring logic from apps into DBMS 2) Enforce constraints  Beyond what constraint system supports  Automatic constraint “repair”  Implementations vary significantly

Trang 1

Constraints & Triggers Triggers –

Introduction

Trang 2

Triggers

Triggers

“Event-Condition-Action Rules”

When event occurs, check condition; if true, do action

1) Move monitoring logic from apps into DBMS

2) Enforce constraints

 Beyond what constraint system supports

 Automatic constraint “repair”

 Implementations vary significantly

This intro: SQL standard

Demo: SQLite

Trang 3

Triggers in SQL

Create Trigger name

Before|After|Instead Of events

[ referencing-variables ]

[ For Each Row ]

When ( condition )

Triggers

Trang 4

Referential Integrity:

R.A references S.B , cascaded delete

Create Trigger Cascade

After Delete On S

Referencing Old Row As O

For Each Row

[ no condition ]

Delete From R Where A = O.B

Triggers

Trang 5

Referential Integrity:

R.A references S.B , cascaded delete

Create Trigger Cascade

After Delete On S

Referencing Old Row As O

[ For Each Row ]

[ no condition ]

Triggers

Trang 6

Referential Integrity:

R.A references S.B , cascaded delete

Create Trigger Cascade

After Delete On S

Referencing Old Table As OT

[ For Each Row ]

[ no condition ]

Delete From R Where A = O.B

Triggers

Trang 7

Referential Integrity:

R.A references S.B , cascaded delete

Create Trigger Cascade

After Delete On S

Referencing Old Table As OT

[ For Each Row ]

[ no condition ]

Triggers

Trang 8

Jennifer Widom

Triggers

Tricky Issues

 Row-level vs Statement-level

– New/Old Row and New/Old Table

– Before, Instead Of

 Multiple triggers activated at same time

 Trigger actions activating other triggers (chaining)

– Also self-triggering, cycles, nested invocations

 Conditions in When vs as part of action

 Implementations vary significantly

Trang 9

T(K,V) – K key, V value

Create Trigger IncreaseInserts

After Insert On T

Referencing New Row As NR, New Table As NT

For Each Row

When (Select Avg(V) From T) <

(Select Avg(V) From NT)

Update T set V=V+10 where K=NR.K

Triggers

Trang 10

Triggers

Triggers

“Event-Condition-Action Rules”

When event occurs, check condition; if true, do action

1) Move monitoring logic from apps into DBMS

2) Enforce constraints

 Beyond what constraint system supports

 Automatic constraint “repair”

 Implementations vary significantly

Ngày đăng: 24/05/2016, 15:19

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w