473,474 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Instead of Trigger

15 New Member
Hi everybody,

i have a view, which contains some columns of two tables. I would like to insert informtions to this view but since this view is created through a join, it is impossible to insert informations to it.

So i decided to use an instead of trigger to do that but i don't know how?

CREATE TABLE Person (
PersonID integer NOT NULL,
Lastname varchar(255) NOT NULL,
Firstname varchar(255) NOT NULL,
Title char(5) NOT NULL WITH DEFAULT 'Dr.',
PRIMARY KEY (PersonID)
)

CREATE TABLE Adress(
PersonID integer NOT NULL,
City varchar(255) NOT NULL,
Postcode char(5) NOT NULL,
Street varchar(255) NOT NULL,
Number integer NOT NULL,
Country varchar(255) NOT NULL WITH DEFAULT 'CANADA',
FOREIGN KEY (PersonID) REFERENCES Person (PersonID)
ON DELETE CASCADE
)

CREATE VIEW PersonView (personid, lastname, firstname, city, Country) AS
SELECT p.personid, p.lastname, p.firstname, a.city, a.country
FROM person AS p
INNER JOIN adress AS a
ON p.personid=a.personid

CREATE TRIGGER PersonTrig instead of insert on PersonView referencing new as n for each row mode db2sql
BEGIN ATOMIC
Insert into person(lastname,firstname) values(n.lastname,n.firstname);
-- How should the insert into adress look like ( i don't know which personid is
-- created in the first part

END

------------------------------------------------------
In the end, the following command should insert data in the view:

insert into PersonView(lastname,firstname,city,country) values('Smith','Ron','London','England');

Could anyone help me please?

thanks in advance.

Best Regards,
Maryan
May 15 '08 #1
0 1268

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Stuart McGraw | last post by:
Is Microsoft full of #*$#*% (again) or am I badly misunderstanding something? Quote from Microsoft's T-SQL doc: > INSTEAD OF triggers are executed instead of the triggering action. > These...
4
by: Dan | last post by:
I am loading data from table A into table B. Certain columns in B have check constraints. I'd like for any rows from A, which violate constraints, to be inserted into a third table, C. When the...
1
by: Alex | last post by:
Hi, I need to create a trigger that will trap the insert commands on a table and if the row already exists, it updates the information. I started with this exemple but im getting syntax...
5
by: William of Ockham | last post by:
Hi, I was asked to recreate a new clean database for our developers because the current one they use is not entirely up to date. So I created a new database and I run into the followin strange...
5
by: Chris | last post by:
I'm attempting to get Instead Of triggers working. My platform in Solaris, DB2 verison 8.1.x (not sure which). If I create two simple tables with 1 row each: create table test_cc_1 (col1...
2
by: leedo | last post by:
Hi, I am almost going crazy with this. I have a table that I bulk insert into from another database using VS2005. I need to change the data in the records before committing the values in the...
18
by: femina | last post by:
i have a problem in understanding the concept which i read ill jus give the snippet code create trigger WORKER_LODG_MANAG_update instead of UPDATE on WORKER_LODG_MANAG for each row begin ...
4
zachster17
by: zachster17 | last post by:
Hello all, I have 2 tables (tblAddProviderProfessional and tblAddProvider). There are other tables such as tblAddProviderFacility and so forth. tblAddProvider is a table that has similar data...
0
by: marieoutayek | last post by:
Hi, I have a problem and I hope that you help me : I have a trigger "tr_view_emp_iu" INSTEAD OF a view "view_employee" the problem is if the changes is done on the field "first_name" in the...
0
Brad Orders
by: Brad Orders | last post by:
Hi all Here is my situation: When table A is updated, I need to record some data in table B, then apply the update to table A Normally I would use a FOR UPDATE trigger, but the table has a...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.