i am studying about views in sql and somewhat confused and having the following query :
i have a table 'item' and need to insert data into it. am using two ways, one without view and the other using a view.
CREATE VIEW vw_item
SELECT * FROM item
Inserting via the view:
INSERT INTO vw_item values(...)
Inserting via the table:
INSERT INTO item values(...)
What's the difference in query 1 and 2? That is, directly inserting into the table & using a view to insert into the table.
Is there a difference in insertion only when we use CHECK OPTION
while creating the view?
There is no difference between the two INSERT statements. Views can be updateable, but there are restrictions on what makes views updateable.
The
CHECK OPTION
prevents changes that do not meet the view's criteria. If your view example had a WHERE clause, the column(s) involved could not be updated -- but other columns in the table could be.Reference