Creating and using views in mariadb
Views can be created in a following simple manner in mariadb using CREATE VIEW keyword followed by SELECT statement as done below
CREATE VIEW view_name AS SELECT column1, column2 FROM table_name WHERE condition;
The above statement creates a view with view_name name which retrieves column1, column2 from table table_name
Now we can query the view as following
SELECT * FROM view_name
Updating Views
Views can also be updatable based on the certain criteria which has to be met (like no subqueries or aggregate functions). If the view is updatable then only the data can be inserted, deleted and updated in a view. Updating the data in a view doesn't actually update the data in a view since view is only the container for select statement instead it updates the data in underlying original tables.
Dropping Views
Finally the views can be dropped as tables, indexes and other objects in databases using DROP statement.
Following is an example of dropping a view
DROP VIEW view_name
Top comments (0)