Click here to Skip to main content
15,943,406 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My table Class_room

SLno--------class-------No_of_seats
001------------11-----------10
002------------10----------08
003------------09----------21

i had to create a view as done below

create view total_seats as select a.SLNo,a.class, count(a.NO_of_seats) from class_room a group by class;


but i'm not able to insert or update

insert into total_seats values('004','12','22');
error as target table total_seats of the INSERT is not insertable-into

or
update total_seats set No_of_seats=12 where class=11;
Error target table of the update is not updatable

i went through this website
https://dev.mysql.com/doc/refman/5.0/en/view-updatability.html[^]
but couldn't understand anything. please help me. how can i insert/update into a view.


Thanks in advance
Posted
Comments
Andy Lanng 8-Jun-15 4:46am    
There are some column types that cannot be updated. Also, rows can only be updated if they map 1 row to 1 table row. This also applies to inserts. Finally (I think) rows cannot be updated / inserted into if the view is missing some table columns that cannot be null.

Please post your view definition, as well as the definitions of any tables in that view and I can be more specific about your issue
raj@hardWork 8-Jun-15 5:57am    
field-----------type-----------null---------key-------default------extra
SLno---------varchar---------yes---------null------------------------
class------char------------yes----------null----------------------
count(no_of_seats)--bigint-------no-----------0-----------------------
raj@hardWork 8-Jun-15 7:41am    
Does this help?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900