473,416 Members | 1,731 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,416 developers and data experts.

opnGauss SQL Syntax - View

19
define view

⚫ A view is a virtual table derived from one or several basic tables, which can be used to control user access to data. The SQL statements involved are shown in the following table.

⚫ Description:

 The view is different from the basic table. The database only stores the definition of the view, not the data corresponding to the view. These data are still stored in the original basic table.

 If the data in the basic table changes, the data queried from the view also changes.

 In this sense, a view is like a window through which data and changes in the database of interest to the user can be seen.



Create a view

⚫ Syntax

CREATE [ OR REPLACE ] [ TEMP | TEMPORARY ] VIEW view_name [ ( column_name [, ...] ) ] [ WITH ( {view_option_name [= view_option_value]} [, ... ] ) ] AS query;

⚫ Example:

 Create the view privilege_view and update the view if it exists.

postgres=# CREATE OR REPLACE VIEW privilege_view AS SELECT b_number, b_type FROM bank_card;

 View the data in the view, the syntax is the same as the query table.

postgres=# SELECT * FROM privilege_view;

 View the view structure.

postgres=# \d privilege_view;

delete view

⚫ Syntax

DROP VIEW [ IF EXISTS ] view_name [, ...] [ CASCADE | RESTRICT ];



⚫ Parameter description

 IF EXISTS

◼ If the view exists, delete it.

 view_name

◼ The view to be deleted.

 CASCADE | RESTRICT

◼ CASCADE: Cascading delete objects that depend on this view (such as other views).

◼ RESTRICT: Refuse to drop this view if any dependent objects exist. This option is the default.

⚫ Example

postgres=# DROP VIEW IF EXISTS privilige_view;
Oct 10 '22 #1
0 8536

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Michael Krzepkowski | last post by:
All, I have a view that returns the following values: Item Vendor 70807 1234 70807 5678 If I am looking for items that have more...
23
by: Carter Smith | last post by:
http://www.icarusindie.com/Literature/ebooks/ Rather than advocating wasting money on expensive books for beginners, here's my collection of ebooks that have been made freely available on-line...
1
by: Jeff Magouirk | last post by:
Dear Group, I am trying to create a view and keep getting the Incorrect syntax near the keyword 'Declare'" error. Here is the code I am writing. Create view fixed_airs (sid, fad_a2, fad_a3)...
4
by: Steve Kallal | last post by:
I am relatively new to the world of ASP .NET programming. So I really don't understand much of the code in the WebForms HTML View. The rendering "<%# %>" syntax does not make much sense to me. I...
7
by: John Øllgård Jensen | last post by:
Hi Using MS Asccess 2000: In a query I'm trying to create a new field with following expression: FilmDate: Left(,4) The field "FilmNo" is another text field in the query. This is...
4
by: cognosqueen | last post by:
I need to create a view of a sql table, but change the data types. I know the syntax below is not correct, and can't figure out if it is wrong or if you just can't do this. I have only created...
4
by: Whit | last post by:
I am having a terrible time trying to create a view. Here is the sql string: $sql = "CREATE VIEW v AS SELECT * FROM t1;"; Here is the error: You have an error in your SQL syntax; check the...
2
by: account locked | last post by:
I have a situation where an SQL View was created over several table - and the library containing the SQL view is going to be refreshed. When the refresh occurs we will lose the SQL view. I do...
0
MMcCarthy
by: MMcCarthy | last post by:
Rather than using the Access design view change the view to SQL. I am going to attempt to outline the general syntax used for SQL queries in Access. Angle brackets <> are used in place of some...
1
by: James Long | last post by:
I am getting the following error: Parse error: syntax error, unexpected $end in E:\wamp\www\forums\view_topic.php on line 138 And i am a newbie.. I have been working on the code for ages and now...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.