SQL Server Create View

Last updated on Dec 19 2021
Amit Warghade

Table of Contents

SQL Server Create View

A view may be a virtual table created consistent with the result set of an SQL statement.

A view contains rows and columns, a bit like a true table. The columns within the view are the columns from one or more real tables within the database. SQL functions, WHERE, and JOIN statements also can be added to the view.

There are two ways to make a view in SQL Server:

  • By using SQL Server management studio UI.
  • By using SQL Server query statement.

By using SQL Server management studio UI

Open SQL Server Management Studio.

Page 1 Image 1 28
SQL Server Management

Here you see view. attend view and click on right.

Page 2 Image 2 15
attend view

Now you’ll see a page like this. Choose a table on which you would like to make a view. Here we select “Student” table.

Page 2 Image 3 9
student

Click on the add button.

A view is made .

By using SQL Server query statement.

Syntax:

  1. CREATE VIEW view_name AS
    SELECT column1, column2, ...
    FROM table_name
    WHERE condition;

SQL Create VIEW Example

Let’s create a view named “Student_name” which contains all data from table “Student” where id is >3.

  1. CREATE VIEW [Student_view] AS
    SELECT id, name, age
    FROM [tecklearn].[dbo].[Student]
    WHERE id > 3;

Output:

Page 4 Image 4 7
create view

View is made successfully.

You can verify that created view:

Page 5 Image 5 7
verify

Now query the view:

  1. SELECT * FROM [Student_view];

Output:

Page 6 Image 6 5
query

Update a View

You can update a view by using ALTER VIEW statement.

Syntax:

  1. CREATE OR REPLACE VIEW view_name AS
    SELECT column1, column2, ...
    FROM table_name
    WHERE condition;

Now add a column “fee” to the created view “Student_view” from the table “Student”. Use the subsequent statement:

  1. ALTER VIEW [Student_view] AS
    SELECT id, name, age, fee
    FROM [tecklearn].[dbo].[Student]
    WHERE id > 3;

Output:

Page 7 Image 7 4
alter view

You can see that view is updated successfully. Verify it by using SELECT statement:

Page 7 Image 8 5
SELECT

Output:

Page 8 Image 9 2
output

SQL Server DROP a View

DROP VIEW command is employed to delete a view.

Syntax:

  1. DROP VIEW view_name;

Example:

Let’s delete the view “Student_view”.

  1. DROP VIEW [Student_view];

Output:

Page 9 Image 10 1
drop view

Now you’ll see that view is deleted.

So, this brings us to the end of blog. This Tecklearn ‘SQL Server Create View’ blog helps you with commonly asked questions if you are looking out for a job in MS-SQL Server. If you wish to learn MS-SQL Server and build a career in Database domain, then check out our interactive, MS-SQL Server Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/ms-sql-server-training-and-certification-course/

MS-SQL Server Training

About the Course

Microsoft SQL Server training course is an online classroom training meant for developers to master the descriptive language to work for relational databases. Important topics included in this SQL course are SQL introduction, relational databases, queries, subqueries, joins, and unions. After completing this course, you will also become proficient in the theory of optimization, transactions, indexing, installing SQL Server, database administration, clustering, implementing programmability objects, designing and implementing database objects, managing database concurrency, and optimizing SQL infrastructure and database objects.

Why Should you take MS-SQL Server Training?

  • The average salary for Sql server developer ranges from approximately $88,666 per year for Database Developer to $115,811 per year for Senior SQL Developer. – Indeed.com
  • Wells Fargo, UPS, US Bank, Perspecta, Silicon Valley Bank, Mindtree Wipro, Infosys & many other MNC’s worldwide use MS SQL Server for their Database deployments.
  • According to Gartner, MS SQL Server is the market leader in the Relational Database with 18.5% market share globally.

What you will Learn in this Course?

Introduction to SQL

  • Various types of databases
  • Introduction to SQL
  • Installation Steps of MS-SQL Server
  • Overview of Microsoft SQL Server Management Studio
  • SQL architecture, client/server relation
  • Database types

Introduction to relational databases, basic concepts of relational tables

  • Working with rows and columns
  • Various operators used like logical and relational
  • Constraints, Primary Key and Foreign Key
  • Insert, Update, Delete, Alter

Working with SQL: Join, Tables, and Variables

  • SQL Operators and Queries
  • SQL functions
  • Creation of Table
  • Retrieval of Data from tables
  • Combining rows from tables using joins
  • Operators such as intersect, except, union, temporary table creation, set operator rules, table variables etc

Deep Dive into SQL Functions

  • Data Retrieval Language
  • Functions
  • Operators
  • Clauses
  • Sub-Queries
  • Correlated Sub-Queries

SQL Views, Functions

  • Sub-queries
  • Views
  • Indexes

Managing Data with Transact-SQL

  • Transact-SQL queries
  • Implementing functions and aggregating data
  • Determining the results of DDL statements on supplied tables and data

Cursor Management and Triggers

  • Cursors
  • Triggers
  • Types of Triggers

Stored Procedures and User Defined functions

  • Understanding of Stored Procedures
  • Key benefits of Stored Procedures
  • Studying user-defined functions

Deep Dive into User-defined Functions

  • Detailed study of user-defined functions
  • Various types of UDFs like Scalar, Inline Table Value, multi-statement Table
  • What is Rank Function? Triggers, when to execute Triggers?

SQL Optimization and Performance

  • Concepts of Concurrency and Locking behaviour
  • Usage of memory-optimized tables to solve issues
  • Examining and Troubleshooting of query plans
  • Performance management of Database instances
  • SQL server Performance Monitoring

Got a question for us? Please mention it in the comments section and we will get back to you.

 

0 responses on "SQL Server Create View"

Leave a Message

Your email address will not be published. Required fields are marked *