Introduction views in SQL server:
In this article, we will discuss the Create views in SQL server with examples and how views are to improve performance
Views In SQL server are it actually saves you a lot of time by actually not building similar tables or same tables for different needs.
Views can be actually created joining multiple tables
create a view in SQL databases means simply we can say we are going to create as a virtual base table
what are the tables we created in database that every table is called a “Base table”
when I’m going to accessing multiple times my base table data it was giving some low performance and reducing your performance.
Views in SQL Server syntax:
CREATE VIEW [ <schema_name>. ] <view_name> [ ( column [, …n ] ) ]
[ WITH { [ENCRYPTION], [SCHEMABINDING], [VIEW_METADATA] } ]
AS <select_statement>
[ WITH CHECK OPTION ]
Download the script and Run Script
But every request I want to send it to my base table and retrieve the data so instead of that now I’m created one “view”
Views in SQL Server with joins
CREATE VIEW [dbo].[V_Orders] AS
select [FirstName],[Customer].[City],[ProductName],[Product].[UnitPrice],[OrderNumber],[CompanyName],[ContactName],[Supplier].[Country]
from [dbo].[Customer] inner join [dbo].[Order]
on [dbo].[Customer].Id=[dbo].[Order].Id inner join
[dbo].[OrderItem] on [dbo].[OrderItem].OrderId=[dbo].[Order].Id inner join
[dbo].[Product] on [dbo].[Product].Id=[dbo].[OrderItem].ProductId inner join
[dbo].[Supplier] on [dbo].[Supplier].Id=[dbo].[Product].SupplierId
GO
select *from V_Orders

the above example what is happening here I am not interacting with the main table or base tables okay it’s not necessary to interact with the base table instead of that I’m going to accessing each and everything through the view
views are a symbol I can say it is a virtual or else even though we can say logical is a virtual or logical table
Views in SQL Examples
Find the total sum of unit-price belongs to the city name “Kirkland” or the base table.
select SUM(V_Orders.UnitPrice)as totalcount from V_Orders where V_Orders.City='kirkland' group by City

Find the details of the order only belongs to the country is “spain”
select *from V_Orders where V_Orders.Country='Spain'

To find the details of the orders which do not belong to the country name “Spain”
select *from V_Orders where V_Orders.Country <>'Spain'
Calculate the total count of order details from the cities
select COUNT(V_Orders.City) as totalcount,City from V_Orders group by V_Orders.City

- how to create ASP.NET Core 3 Web API Project - January 21, 2022
- JWT Authentication using OAUTH - January 10, 2022
- Ado.net database Transactions - January 9, 2022
Bookmarked!, I love your website!
First time visiting your website, I enjoy your web site!
Google
Please go to the web sites we adhere to, like this one, thanks