Subject | How to make a read-only view updatable |
---|---|
Author | xaladjov |
Post date | 2002-09-05T07:09:34Z |
Is it possible to make un read-only view - based on multiple tables
updatable? I try to use triggers that change base tables but they
does not fire.
CREATE TABLE PrimaryTable
(ID INTEGER NOT NULL,
CONSTRAINT PrimaryKey_pk PRIMARY KEY (ID),
Val INTEGER);
CREATE TABLE Table1 (
ID INTEGER NOT NULL,
CONSTRAINT Table1_pk PRIMARY KEY(ID),
CONSTRAINT Table1_fk FOREIGN KEY (ID) REFERENCES PrimaryTable(ID) ON
DELETE CASCADE,
Val INTEGER);
CREATE TABLE Table2 (
ID INTEGER NOT NULL,
CONSTRAINT Table2_pk PRIMARY KEY(ID),
CONSTRAINT Table2_fk FOREIGN KEY (ID) REFERENCES Table1(ID) ON DELETE
CASCADE,
Val INTEGER);
CREATE VIEW View0 (ID, VAL) AS
SELECT ID, Val
FROM PrimaryTable;
/*This view is updatable but it is based on a single table*/
CREATE VIEW View1 (ID, VAL1, VAL2) AS
SELECT P.ID, P.Val, T1.VAL
FROM PrimaryTable P, Table1 T1
WHERE P.ID = T1.ID;
CREATE VIEW View2 (ID, VAL1, VAL2, VAL3) AS
SELECT P.ID, P.Val, T1.Val, T2.Val
FROM PrimaryTable P, Table1 T1, Table2 T2
WHERE P.ID = T1.ID AND T2.ID = T1.ID;
SET TERM ; ^
CREATE PROCEDURE Update_View1(ID INTEGER, Value1 INTEGER, Value2
INTEGER) AS
BEGIN
UPDATE Table1 SET Val = :Value2 WHERE ID = :ID;
SUSPEND;
END
^
/* I try to execute this stored procedure manually with
QMS QuickDesktop and it seems to work properly
CREATE TRIGGER BeforeUpdate_View1 FOR View1 ACTIVE BEFORE UPDATE
POSITION 0 AS
BEGIN
EXECUTE PROCEDURE Update_View1(new.ID,new.Val1,new.Val2);
END
^
CREATE TRIGGER AfterUpdate_View1 FOR View1 ACTIVE AFTER UPDATE
POSITION 0 AS
BEGIN
EXECUTE PROCEDURE Update_View1(new.ID,new.Val1,new.Val2);
END
^
SET TERM ; ^
The one week old question for me is how to make View1 or View2 updatable.
Thank you in advance
Hristo Aladjov
updatable? I try to use triggers that change base tables but they
does not fire.
CREATE TABLE PrimaryTable
(ID INTEGER NOT NULL,
CONSTRAINT PrimaryKey_pk PRIMARY KEY (ID),
Val INTEGER);
CREATE TABLE Table1 (
ID INTEGER NOT NULL,
CONSTRAINT Table1_pk PRIMARY KEY(ID),
CONSTRAINT Table1_fk FOREIGN KEY (ID) REFERENCES PrimaryTable(ID) ON
DELETE CASCADE,
Val INTEGER);
CREATE TABLE Table2 (
ID INTEGER NOT NULL,
CONSTRAINT Table2_pk PRIMARY KEY(ID),
CONSTRAINT Table2_fk FOREIGN KEY (ID) REFERENCES Table1(ID) ON DELETE
CASCADE,
Val INTEGER);
CREATE VIEW View0 (ID, VAL) AS
SELECT ID, Val
FROM PrimaryTable;
/*This view is updatable but it is based on a single table*/
CREATE VIEW View1 (ID, VAL1, VAL2) AS
SELECT P.ID, P.Val, T1.VAL
FROM PrimaryTable P, Table1 T1
WHERE P.ID = T1.ID;
CREATE VIEW View2 (ID, VAL1, VAL2, VAL3) AS
SELECT P.ID, P.Val, T1.Val, T2.Val
FROM PrimaryTable P, Table1 T1, Table2 T2
WHERE P.ID = T1.ID AND T2.ID = T1.ID;
SET TERM ; ^
CREATE PROCEDURE Update_View1(ID INTEGER, Value1 INTEGER, Value2
INTEGER) AS
BEGIN
UPDATE Table1 SET Val = :Value2 WHERE ID = :ID;
SUSPEND;
END
^
/* I try to execute this stored procedure manually with
QMS QuickDesktop and it seems to work properly
CREATE TRIGGER BeforeUpdate_View1 FOR View1 ACTIVE BEFORE UPDATE
POSITION 0 AS
BEGIN
EXECUTE PROCEDURE Update_View1(new.ID,new.Val1,new.Val2);
END
^
CREATE TRIGGER AfterUpdate_View1 FOR View1 ACTIVE AFTER UPDATE
POSITION 0 AS
BEGIN
EXECUTE PROCEDURE Update_View1(new.ID,new.Val1,new.Val2);
END
^
SET TERM ; ^
The one week old question for me is how to make View1 or View2 updatable.
Thank you in advance
Hristo Aladjov