Blog

News & Events, Quick Tips
How to Create SQL view in Odoo 15
April 5, 2022
Difference between Table and View in SQL
SQL stores data in a database in the form of rows, and columns called the table. The data from a table can be retrieved using SQL queries. A table has related data for which the table was initially created. The table is stored in the database. A view is a query that contains data from multiple tables joined using SQL queries arranged in table format. The view is not stored in the database; whenever the data is to be viewed, the related query to generate the view is run. This is useful when a set of data is frequently required but requires data from multiple tables to be joined together.SQL view in Odoo
As mentioned in the previous section, when a set of data from multiple database tables has frequently required. A view can be used as it is much faster than the ORM search methods in handing data from multiple tables as ORM searching can take more time.Creating SQL view in Odoo 15
Odoo uses SQL queries to get data from the database and uses the views in Odoo to display the data. We will create a view in Odoo mostly it is a tree view as it resembles the table layout in which SQL returns data and since it is easier to interpret multiple data from multiple records.Create the model as normally you create for Odoo, just that an additional _auto=False is added in the model definition.

_auto = False is given in the model definition to specify that notable needs to be created for this model in the database.
Creating the view for the user needs to create a tree view, an action, and a menu item, as usually done when creating views for the models in Odoo.

To open the view for the SQL view, navigate to Odoo and click the menu item for the view.
