DEV Community

Syed Umer Tariq
Syed Umer Tariq

Posted on

1

Views In Mariadb (part 2)

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay