-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed After and Instead of trigger issues on table
1. If an After trigger exists on table, it is skipped after instead of trigger is fired on same table in Babelfish. 2. Query execution and After trigger is skipped on table in babelfish when it has a disabled Instead of Trigger Task: BABEL-4672 and BABEL-4801 Signed-off-by: Deepakshi Mittal <[email protected]>
- Loading branch information
1 parent
0efbb15
commit 4e04208
Showing
21 changed files
with
632 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
DROP TABLE IF EXISTS tbl_emp_salary; | ||
GO | ||
|
||
DROP TABLE IF EXISTS emp_salary; | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE emp_salary(emp_id int, salary int); | ||
GO | ||
|
||
CREATE TABLE tbl_emp_salary(emp_id int, salary int); | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,354 @@ | ||
----------- Section 1 IOT INSERT Triggers | ||
-- IOT INSERT TRIGGER -> AFTER INSERT TRIGGER | ||
CREATE TRIGGER tr_emp_salary_instead_insert ON emp_salary | ||
INSTEAD OF INSERT | ||
AS | ||
INSERT INTO emp_salary VALUES(2, 2000); | ||
GO | ||
|
||
CREATE TRIGGER tr_emp_salary_after_insert ON emp_salary | ||
AFTER INSERT | ||
AS | ||
INSERT INTO emp_salary VALUES(3, 3000); | ||
GO | ||
|
||
INSERT INTO emp_salary VALUES (1,1000); | ||
GO | ||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
|
||
SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; | ||
GO | ||
~~START~~ | ||
int#!#int | ||
2#!#2000 | ||
3#!#3000 | ||
~~END~~ | ||
|
||
|
||
DROP TRIGGER tr_emp_salary_after_insert; | ||
GO | ||
|
||
DROP TRIGGER tr_emp_salary_instead_insert; | ||
GO | ||
|
||
-- IOT INSERT TRIGGER -> AFTER UPDATE TRIGGER | ||
CREATE TRIGGER tr_emp_salary_instead_insert ON emp_salary | ||
INSTEAD OF INSERT | ||
AS | ||
UPDATE emp_salary SET salary = salary + 999 where emp_id = 2; | ||
GO | ||
|
||
CREATE TRIGGER tr_emp_salary_after_update ON emp_salary | ||
AFTER UPDATE | ||
AS | ||
UPDATE emp_salary SET salary = salary + 9999 where emp_id = 2; | ||
GO | ||
|
||
INSERT INTO emp_salary VALUES (4,4000); | ||
GO | ||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
|
||
SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; | ||
GO | ||
~~START~~ | ||
int#!#int | ||
2#!#12998 | ||
3#!#3000 | ||
~~END~~ | ||
|
||
|
||
DROP TRIGGER tr_emp_salary_after_update; | ||
GO | ||
|
||
DROP TRIGGER tr_emp_salary_instead_insert; | ||
GO | ||
|
||
-- IOT INSERT TRIGGER -> AFTER DELETE TRIGGER | ||
CREATE TRIGGER tr_emp_salary_instead_insert ON emp_salary | ||
INSTEAD OF INSERT | ||
AS | ||
DELETE FROM emp_salary where emp_id = (SELECT emp_id from INSERTED); | ||
GO | ||
|
||
CREATE TRIGGER tr_emp_salary_after_delete ON emp_salary | ||
AFTER DELETE | ||
AS | ||
DELETE FROM emp_salary where emp_id = (SELECT emp_id -1 from DELETED); | ||
GO | ||
|
||
INSERT INTO emp_salary VALUES (3,1000); | ||
GO | ||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
|
||
SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; | ||
GO | ||
~~START~~ | ||
int#!#int | ||
~~END~~ | ||
|
||
|
||
DROP TRIGGER tr_emp_salary_after_delete; | ||
GO | ||
|
||
DROP TRIGGER tr_emp_salary_instead_insert; | ||
GO | ||
|
||
TRUNCATE TABLE emp_salary; | ||
GO | ||
|
||
----------- Section 2 IOT UPDATE Triggers | ||
-- IOT UPDATE TRIGGER -> AFTER INSERT TRIGGER | ||
INSERT INTO emp_salary VALUES (1, 1000); | ||
GO | ||
~~ROW COUNT: 1~~ | ||
|
||
|
||
CREATE TRIGGER tr_emp_salary_instead_update ON emp_salary | ||
INSTEAD OF UPDATE | ||
AS | ||
INSERT INTO emp_salary VALUES(2, 2000); | ||
GO | ||
|
||
CREATE TRIGGER tr_emp_salary_after_insert ON emp_salary | ||
AFTER INSERT | ||
AS | ||
INSERT INTO emp_salary VALUES(3, 3000); | ||
GO | ||
|
||
UPDATE emp_salary SET salary = salary + 5 where emp_id = 1; | ||
GO | ||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
|
||
SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; | ||
GO | ||
~~START~~ | ||
int#!#int | ||
1#!#1000 | ||
2#!#2000 | ||
3#!#3000 | ||
~~END~~ | ||
|
||
|
||
DROP TRIGGER tr_emp_salary_after_insert; | ||
GO | ||
|
||
DROP TRIGGER tr_emp_salary_instead_update; | ||
GO | ||
|
||
-- IOT UPDATE TRIGGER -> AFTER UPDATE TRIGGER | ||
CREATE TRIGGER tr_emp_salary_instead_update ON emp_salary | ||
INSTEAD OF UPDATE | ||
AS | ||
UPDATE emp_salary SET salary = salary + 999 where emp_id = 2; | ||
GO | ||
|
||
CREATE TRIGGER tr_emp_salary_after_update ON emp_salary | ||
AFTER UPDATE | ||
AS | ||
UPDATE emp_salary SET salary = salary + 9999 where emp_id = 2; | ||
GO | ||
|
||
UPDATE emp_salary SET salary = salary + 5 where emp_id = 2; | ||
GO | ||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
|
||
SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; | ||
GO | ||
~~START~~ | ||
int#!#int | ||
1#!#1000 | ||
2#!#12998 | ||
3#!#3000 | ||
~~END~~ | ||
|
||
|
||
DROP TRIGGER tr_emp_salary_after_update; | ||
GO | ||
|
||
DROP TRIGGER tr_emp_salary_instead_update; | ||
GO | ||
|
||
-- IOT UPDATE TRIGGER -> AFTER DELETE TRIGGER | ||
CREATE TRIGGER tr_emp_salary_instead_update ON emp_salary | ||
INSTEAD OF UPDATE | ||
AS | ||
DELETE FROM emp_salary where emp_id = (SELECT emp_id from INSERTED) | ||
GO | ||
|
||
CREATE TRIGGER tr_emp_salary_after_delete ON emp_salary | ||
AFTER DELETE | ||
AS | ||
DELETE FROM emp_salary where emp_id = (SELECT emp_id +1 from DELETED) | ||
GO | ||
|
||
UPDATE emp_salary SET salary = salary + 5 where emp_id = 1; | ||
GO | ||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
|
||
SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; | ||
GO | ||
~~START~~ | ||
int#!#int | ||
3#!#3000 | ||
~~END~~ | ||
|
||
|
||
DROP TRIGGER tr_emp_salary_after_delete; | ||
GO | ||
|
||
DROP TRIGGER tr_emp_salary_instead_update; | ||
GO | ||
|
||
TRUNCATE TABLE emp_salary; | ||
GO | ||
|
||
----------- Section 3 IOT DELETE Triggers | ||
-- IOT DELETE TRIGGER -> AFTER INSERT TRIGGER | ||
INSERT INTO emp_salary VALUES(1, 1000); | ||
GO | ||
~~ROW COUNT: 1~~ | ||
|
||
|
||
CREATE TRIGGER tr_emp_salary_instead_delete ON emp_salary | ||
INSTEAD OF DELETE | ||
AS | ||
INSERT INTO emp_salary VALUES(2, 2000); | ||
GO | ||
|
||
CREATE TRIGGER tr_emp_salary_after_insert ON emp_salary | ||
AFTER INSERT | ||
AS | ||
INSERT INTO emp_salary VALUES(3, 3000); | ||
GO | ||
|
||
DELETE FROM emp_salary where emp_id = 1; | ||
GO | ||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
|
||
SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; | ||
GO | ||
~~START~~ | ||
int#!#int | ||
1#!#1000 | ||
2#!#2000 | ||
3#!#3000 | ||
~~END~~ | ||
|
||
|
||
DROP TRIGGER tr_emp_salary_after_insert; | ||
GO | ||
|
||
DROP TRIGGER tr_emp_salary_instead_delete; | ||
GO | ||
|
||
-- IOT DELETE TRIGGER -> AFTER UPDATE TRIGGER | ||
CREATE TRIGGER tr_emp_salary_instead_delete ON emp_salary | ||
INSTEAD OF DELETE | ||
AS | ||
UPDATE emp_salary SET salary = salary + 999 where emp_id = 2; | ||
GO | ||
|
||
CREATE TRIGGER tr_emp_salary_after_update ON emp_salary | ||
AFTER UPDATE | ||
AS | ||
UPDATE emp_salary SET salary = salary + 9999 where emp_id = 2; | ||
GO | ||
|
||
DELETE FROM emp_salary where emp_id = 1; | ||
GO | ||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
|
||
SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; | ||
GO | ||
~~START~~ | ||
int#!#int | ||
1#!#1000 | ||
2#!#12998 | ||
3#!#3000 | ||
~~END~~ | ||
|
||
|
||
DROP TRIGGER tr_emp_salary_after_update; | ||
GO | ||
|
||
DROP TRIGGER tr_emp_salary_instead_delete; | ||
GO | ||
|
||
-- IOT DELETE TRIGGER -> AFTER DELETE TRIGGER | ||
CREATE TRIGGER tr_emp_salary_instead_delete ON emp_salary | ||
INSTEAD OF DELETE | ||
AS | ||
DELETE FROM emp_salary where emp_id = 2; | ||
GO | ||
|
||
CREATE TRIGGER tr_emp_salary_after_delete ON emp_salary | ||
AFTER DELETE | ||
AS | ||
DELETE FROM emp_salary where emp_id = 3; | ||
GO | ||
|
||
DELETE FROM emp_salary where emp_id = 1; | ||
GO | ||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
|
||
SELECT emp_id, salary FROM emp_salary ORDER BY emp_id; | ||
GO | ||
~~START~~ | ||
int#!#int | ||
1#!#1000 | ||
~~END~~ | ||
|
||
|
||
DROP TRIGGER tr_emp_salary_after_delete; | ||
GO | ||
|
||
DROP TRIGGER tr_emp_salary_instead_delete; | ||
GO | ||
|
||
TRUNCATE TABLE emp_salary; | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
DROP TABLE IF EXISTS tbl_emp_salary; | ||
GO | ||
|
||
DROP TABLE IF EXISTS emp_salary; | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE emp_salary(emp_id int, salary int); | ||
GO | ||
|
||
CREATE TABLE tbl_emp_salary(emp_id int, salary int); | ||
GO |
Oops, something went wrong.