Forum Moderators: coopster
I would like to insert data into a view which is 4 tables combined. The 4 tables have relationships, but nothing that is enforced by the database.
Normally when not using a view i would use the primary key from one table as the foreign key in another table, but when i am inserting into a view , i do not have any details of the primary key as i have not inserted the record yet. so i cannot create the relationship.
I am using myisam
What is the best way to create relationships between records in different tables, when you insert information using views?
and
is it possible to retrieve the insert id from all tables where data is being inserted?
29.6.6: Can you insert into views that are based on joins?It is possible, provided that your
INSERTstatement has a column list that makes it clear there's only one table involved.You cannot insert into multiple tables with a single insert on a view.
Some views are updatable. That is, you can use them in statements such asUPDATE,DELETE, orINSERTto update the contents of the underlying table. For a view to be updatable, there must be a one-to-one relationship between the rows in the view and the rows in the underlying table.
Resources:
MySQL 5.1 FAQ — Views [dev.mysql.com]
CREATE VIEW Syntax [dev.mysql.com]
You may consider a Stored Procedure [dev.mysql.com] instead.