SQL - Create View
SQL - Create View
The data in the view does not exist in the database physically. A view is typically created
by the database administrator and is used to −
Structure data in a way that users or classes of users find natural or intuitive.
Restrict access to the data in such a way that a user can see and (sometimes)
modify exactly what they need and no more.
Summarize data from various tables which can be used to generate reports.
Syntax
Following is the syntax of the SQL CREATE VIEW statement −
Example
Assume we have created a table named CUSTOMERS using the CREATE TABLE statement
using the following query −
Open Compiler
Now, insert values into this table using the INSERT statement as follows −
Open Compiler
Verification
You can verify the contents of a view using the select query as shown below −
Learn SQL in-depth with real-world projects through our SQL certification course. Enroll
and become a certified expert to boost your career.
Verification
Following are the contents of the above created view −
If they do not satisfy the condition(s), the UPDATE or INSERT statements return an error.
The following example creates the view named BUYERS_VIEW with the WITH CHECK
OPTION clause.
The WITH CHECK OPTION in this case should deny the entry and updates of the of records
whose age value is greater than or equal to 25.
Verification
Following are the contents of the above created view −
NAME AGE
Ramesh 32
Khilan 25
Chaitali 25
Hardik 27