当前位置:网站首页>SQL Server view
SQL Server view
2022-06-26 05:57:00 【weixin_ forty-seven million two hundred and fifty-four thousand】
Writing time :2022 year 5 month 26 Japan
SQL Server View
Views are named queries stored in the database directory , Allow clients to reference it later . A view graph can contain columns from multiple tables using joins , You can also include only a subset of the columns of a single table . This makes views useful for abstracting or hiding complex queries .
Views have the following advantages :
Security
You can restrict users' direct access to tables , And allow them to access a subset of the data through the view . for example , You can allow users to access customer names through views , Telephone , E-mail , But restrict their access to bank accounts and other sensitive information .
Simple
A relational database can have many tables with complex relationships , for example , One to one and one to many make navigation difficult . however , You can use a set of views to simplify complex queries with joins and conditions .
Uniformity
Sometimes , You need to write complex formulas or logic in each query . To make it consistent , You can hide the complex query logic and calculations in the view . After defining the view , You can reference logic from views , Instead of rewriting it in a separate query .
SQL Server Create view :
SQL Server Create a new view : Use create view sentence :
create view [or alter] schema_name.view_name [(column_list)] as select_statement;
In the above grammar :
stay create view Keyword to specify the name of the view .schema_name Is the name of the schema to which the view belongs . Specify definition as Keyword after the view select sentence (select_statement).select Statement can reference one or more tables . If the column list of the view is not explicitly specified ,SQL Server Will use from select Statement .、
If you want to redefine the view , for example , Add more columns to it or remove some from it , Can be in create view Use after keyword or alter keyword .
Create a simple view example :
The following statement is based on orders,order_time and products Table creation name is daily_sales The view of :
create view sales.daily_sales as select
year(order_date )as y,
month(order_date ) as m,
day(order_date ) as d,
p.product_id,
product_name,
quantity * i.list_price as sales
from
sales.order_id as o
inner join sales.order_items as i
on o.order_id = i.order_id
inner join production.products as p
on p.product_id = i.product_id;
establish daily_sales After view , You can use simple select Statement to query data against the underlying table on the view :
select
*
from
sales.daily_sales
order by
y, m , d, product_name;
SQL Server Rename view
Before renaming the view , It must be noted that all view dependent objects can fail . These objects include stored procedures , User defined functions , trigger , Inquire about , Other views and client applications . therefore , After renaming the view , You must ensure that all objects to which the old name of the view is applied use the new name .
Use SSMS Rename view
To rename the name of the view , Follow these steps :
First , In object Explorer (Server Server Management Studio) in , an “ database ”, Select the database name that contains the view you want to rename , And then unfold “ View ” Folder . secondly , Right click the view you want to rename , And then choose “ rename ”
Use SQL Rename view
If you want to rename the view programmatically , have access to sp_rename stored procedure :
exec sp_rename
@objname = ‘sales.product_catalog’,
@newname =’sales.product_list’;
边栏推荐
猜你喜欢

MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications

Selective Search for Object Recognition 论文笔记【图片目标分割】

pytorch(环境、tensorboard、transforms、torchvision、dataloader)

How to associate wechat applet QR code to realize two code aggregation

bingc(继承)

Gram matrix

Consul服务注册与发现

Redis底层数据结构

How to use the tablet as the second extended screen of the PC

pytorch(网络模型)
随机推荐
A love that never leaves
Upgrading technology to art
机器学习 05:非线性支持向量机
Spark source code analysis (I): RDD collection data - partition data allocation
MySQL database-01 database overview
Machine learning 05: nonlinear support vector machines
Something about MariaDB
BOM文档
小程序第三方微信授权登录的实现
Record how to modify the control across threads
类和对象的学习
Lesson 4 serial port and clock
怎么把平板作为电脑的第二扩展屏幕
numpy.exp()
Vs2022 offline installation package download and activation
numpy.log
SQL query time period content
家庭记账程序(第一版)
one billion two hundred and twelve million three hundred and twelve thousand three hundred and twenty-one
Describe an experiment of Kali ARP in LAN