Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does deleting row from view delete row from base table - MySQL?

Tags:

sql

mysql

Deleting a row from a view, will it delete the appropriate rows from the base tables that the view was created upon? I am using MySQL.

like image 514
fiktionvt Avatar asked Dec 03 '09 15:12

fiktionvt


People also ask

Can I delete row from view?

If you want a row to disappear from a view, you need to either delete the data from the real tables behind the view, or alter the view-creating SQL so that that particular row won't be shown in the view.

What happens when you delete a base table that belongs to a view?

Deleting a row in a table will affect the results from regular views. Views are not executed when they are created. They are executed when they are referenced. Each time you reference the view in the query, it is run again.

How do I delete a specific row in MySQL?

To delete rows in a MySQL table, use the DELETE FROM statement: DELETE FROM products WHERE product_id=1; The WHERE clause is optional, but you'll usually want it, unless you really want to delete every row from the table.


1 Answers

Yes, it will. The only thing to watch out for, is permissions.

Quoting official docs

Some views are updatable. That is, you can use them in statements such as UPDATE, DELETE, or INSERT to 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. There are also certain other constructs that make a view nonupdatable.

like image 107
Terry Felkrow Avatar answered Sep 24 '22 12:09

Terry Felkrow