Let us query the view to see its contents: SELECT * The view has been given the name Price_View2 and includes only the price column of the Price table. Let us create a view that included only one column of the Price table: CREATE VIEW Price_View2 AS Here, we can add only one column to the view. Let us query it to see its contents: SELECT *Įven though the base table has 4 records, only 2 were added to the view. The view has been given the name Price_View. Only the records where the price is greater than 200 will be added to the view. The above command will create a view based on the SELECT statement. Let us create a view from the above table: CREATE VIEW Price_View AS The WHERE condition(s) are options, and they must be satisfied for any record to be added to the view. The view-name parameter is the name of the view that you need to create. If omitted and the view already exists, an error will be returned. The OR REPLACE parameter will replace the view if it already exists. Here is the syntax for this statement: CREATE VIEW view-name AS To create a PostgreSQL view, we use the CREATE VIEW statement. In this PostgreSQL Tutorial, you will learn the following: When creating a view, you just need to create a query then give it a name, making it a useful tool for wrapping complex and commonly used queries. The tables are referred to as base tables. A view can also be a representation of more than one table. A view can have all or some of the table columns. However, we can SELECT it as an ordinary table. This means that a view is not a real table.
0 Comments
Leave a Reply. |