i have created a table name "viewex"
create table viewex(
sno int,
name varchar(30),
email varchar(30),
address varchar(50),
contact varchar(30)
);
Inserted data to the table.
Now I am intrested to insert data only for 3 columns (name, address, contact):
insert into viewex(name, address, contact) values('celcabs', 'good', 'bad');
Now the issue is.......... Is it possible to create the view for the query
insert into viewex(name, address, contact) values('celcabs', 'good', 'bad');
You can insert rows into a view only if the view is modifiable and contains no derived columns. The reason for the second restriction is that an inserted row must provide values for all columns, but the database server cannot tell how to distribute an inserted value through an expression.
you cannot insert record into complex view(means select query with joins). But you can insert records by creating INSTEAD of trigger on the view. You can use below code for your issue. But be sure on primary keys that your going to insert, if any on the table.
A view is actually a composition of a table in the form of a predefined SQL query. A view can contain all rows of a table or select rows from a table. A view can be created from one or many tables which depends on the written SQL query to create a view.
In MySQL, views are not only query-able but also updatable. It means that you can use the INSERT or UPDATE statement to insert or update rows of the base table through the updatable view. In addition, you can use DELETE statement to remove rows of the underlying table through the view.
As of PostgreSQL 9.3 you can insert into and update "simple views": http://www.postgresql.org/docs/9.3/static/sql-createview.html
What you're looking for is an updatable view
and postgresql doesn't have direct support for them.
You can get the effect using CREATE RULE - that page has info on how to get the effect of an updatable view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With