SQL VIEWS


SQL Views | SQL Tutorial | Minigranth

SQL VIEW : Introduction

  • SQL VIEW is an advance SQL QUERY used to create and store data in an abstract manner. It means, separate tables containing rows and columns are generated which contains only the data or values which are relevant for users and nothing else.
  • VIEW in SQL are created to make data more structured and user friendly. Also, it allows only specific data to be displayed to users which help in various security releases.
  • Following are the commands that can be used in SQL VIEW.
    • Creating VIEW.
    • Updating VIEW.
    • Dropping VIEW.

Creating SQL VIEW

  • The “CREATE VIEW” command is used to create a new view using either a single table or multiple tables. Below is the syntax for the command.

Syntax : CREATE VIEW VIEW_NAME AS SELECT Column_Name1 , Column_Name2 From Table_Name Where “Condition”.

 

Query : CREATE VIEW Details AS SELECT * From student_details Where Marks>50;

NOTE : The above query will create a view named as “Details” containing records having marks>50 from student_details table.

Updating SQL VIEW

  • The “UPDATE VIEW” command is used to update the values of rows present in existing view. Below is the syntax for the command.

Syntax : UPDATE VIEW_NAME SET Condition Where “Existing Values/Conditions”;

 

Query : UPDATE Details SET Marks = 95 Where Name = ”Rakesh”;

NOTE : The above query will update value in marks in the previously created “Details” View.

Dropping SQL VIEW

  • The “DROP VIEW” command is used to completely delete the existing view. Below is the syntax for the command.

Syntax : DROP VIEW VIEW_NAME;

 

Query : DROP VIEW Details;

NOTE :

  1. Details” VIEW was created first, then the values were updated and now it is dropped.
  2. In all the above queries, we had used “Details” as VIEW Name.